Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dwayne A 97 posts 117 karma points
    Feb 10, 2011 @ 20:00
    Dwayne A
    0

    Recursive Macro for Related links

    Yeah, yeah, I know, there are others who have addressed this issue here, but after trying them all, none seem to solve the problem for me.

    I need to create several link menus that are global/identical on ALL my sites pages, Each link list contains mulitiple external links. This should be a no brainer to maintain in the backend, so related links is to my mind the best way to to this (although link titles and other attributes won't be possible out of the box). On that note, if you have other ideas, feel free to come with suggestions.

    I've put the macro in my master template. With that said, how to? I've used 4.6.1's built-in related links xslt:

      <!-- Input the related links property alias here -->
      <xsl:variable name="propertyAlias" select="string('maalgrupper')"/>
      
      <xsl:template match="/">

        <!-- The fun starts here -->
        <ul>
          <xsl:for-each select="$currentPage/* [name() = $propertyAlias and not(@isDoc)]/links/link">
            <li>
              <xsl:element name="a">
                <xsl:if test="./@newwindow = '1'">
                  <xsl:attribute name="target">_blank</xsl:attribute>
                </xsl:if>
                <xsl:choose>
                  <xsl:when test="./@type = 'external'">
                    <xsl:attribute name="href">
                      <xsl:value-of select="./@link"/>
                    </xsl:attribute>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:attribute name="href">
                      <xsl:value-of select="umbraco.library:NiceUrl(./@link)"/>
                    </xsl:attribute>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:value-of select="./@title"/>
              </xsl:element>
            </li>
          </xsl:for-each>
        </ul>

        <!-- Live Editing support for related links. -->
        <xsl:value-of select="umbraco.library:Item($currentPage/@id,$propertyAlias,'')" />

      </xsl:template>

     

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Feb 28, 2011 @ 14:01
    Lee Kelleher
    1

    Hi Dwayne, (I know you posted this 3 weeks ago - its only just caught my eye)

    There are a few ways to do recursive properties in XSLT... couple for starters:

    This one tried to find the actual property recurisvely...

    <xsl:for-each select="$currentPage/ancestor-or-self::*[name() = $propertyAlias and not(@isDoc) and count(links/link) &gt; 0]/links/link">

    While this next one does the recursive on the document node instead...

    <xsl:for-each select="$currentPage/ancestor-or-self::*[@isDoc and string(*[name() = $propertyAlias]) != ''][1]/*[name() = $propertyAlias]/links/link">

    Try either of the above - one of them should work! ;-)

    Although if your links are set at the homepage level - then you could use that directly?

    <xsl:for-each select="$currentPage/ancestor-or-self::*[@level = 1]/*[name() = $propertyAlias]/links/link">

    ... and one last one ... if you already know the name of the property, then use it that directly too?

    <xsl:for-each select="$currentPage/ancestor-or-self::*[@level = 1]/maalgrupper/links/link">

    Good luck!

    Cheers, Lee.

  • Dwayne A 97 posts 117 karma points
    Feb 28, 2011 @ 18:17
    Dwayne A
    0

    Hey Lee,

    I got this ironed out already, although I cannot recall how, exactly. I really appreciate the explanation! It helps clear up a couple things. Thanks for your help.

Please Sign in or register to post replies

Write your reply to:

Draft