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?
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-eachselect="$currentPage/ancestor-or-self::* [@isDoc][@level=1]/* [name() = $propertyAlias and not(@isDoc)]/links/link">
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
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!
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
Thanks Tom, the above code worked for me. I think I missed a few key bits, like @level=1.
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
Thanks I have figured out the issue :)
is working on a reply...