Copied to clipboard

Flag this post as spam?

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


  • Henrik 12 posts 32 karma points
    Mar 11, 2011 @ 14:53
    Henrik
    0

    Home page Related links property - on every page

    Hi All,

    I'm struggling to get the links in a Related links field to appear on every page in my site. I want to be able to add the links on the home page, and then appear on every other page as well. I've tried a few examples on the forum; but they either don't work in my case - or I'm just not getting something in XSLT. Here's my code

    <xsl:param name="currentPage"/>
      
      <!-- Input the related links property alias here -->
      <xsl:variable name="propertyAlias" select="string('myLinks')"/>
      
      <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>


    This works fine on the home page - but I want the same links added on the home page to appear on every page. What exactly do I need to always go of the home (or root) page?

    (Umbraco 4.6.1)

    Thanks very much for any help!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 11, 2011 @ 15:34
    Tom Fulton
    0

    Hi,

    Your for-each loop is always looking on the current page.  To show the links from the homepage on every page, you'll need to adjust the XPath to select from the homepage instead.

    Try something like this, assuming your homepage is at level 1.

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

    Hope this helps,
    Tom

  • Henrik 12 posts 32 karma points
    Mar 14, 2011 @ 14:24
    Henrik
    0

    Thanks Tom, the above code worked for me. I think I missed a few key bits, like @level=1.

  • Moran 285 posts 934 karma points
    Dec 08, 2012 @ 12:27
    Moran
    0

    How did you put the macro in the home page? I put the macro in the home page template and added some links but I can't see nothing

  • Moran 285 posts 934 karma points
    Dec 08, 2012 @ 12:37
    Moran
    0

    Thanks I have figured out the issue :)

Please Sign in or register to post replies

Write your reply to:

Draft