Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I've seen some examples in the forum but haven't gotten any of them to work with my xslt navigation.
<xsl:output method="xml" omit-xml-declaration="yes" /> <xsl:param name="currentPage"/> <xsl:variable name="level" select="1"/> <xsl:template match="/"> <li> <a href="/">Home</a> </li> <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(showInNavigation) = '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id"> <xsl:attribute name="class">active</xsl:attribute> </xsl:if> <xsl:value-of select="@nodeName"/> </a> </li> </xsl:for-each> </xsl:template>
This is what I have so far. As you can see the 'home' button is outside the loop and therefore not highlighted when clicked like the other pages. How can I incorporate the 'home' button into the navigation of the sub nodes?
I appreciate your help!
I'm sorry for beeing too hasty, I solved it myself. I added this line above template:
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
And added this before the for each loop:
<!-- Home node added here --> <li> <a href="{umbraco.library:NiceUrl($siteRoot/@id)}"> <xsl:if test="$currentPage/@id = $siteRoot/@id"> <xsl:attribute name="class">active</xsl:attribute> </xsl:if> <xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/> </a> </li>
This is the final code of my top navigation menu which highlights the home link:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets "> <xsl:output method="xml" omit-xml-declaration="yes" /> <xsl:param name="currentPage"/> <xsl:variable name="level" select="1"/> <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" /> <xsl:template match="/"> <!-- Home node added here --> <li> <a href="{umbraco.library:NiceUrl($siteRoot/@id)}"> <xsl:if test="$currentPage/@id = $siteRoot/@id"> <xsl:attribute name="class">active</xsl:attribute> </xsl:if> <xsl:value-of select="$currentPage/ancestor-or-self::*/@nodeName"/> </a> </li> <!-- Sub nodes added here --> <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(showInNavigation) = '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id"> <xsl:attribute name="class">active</xsl:attribute> </xsl:if> <xsl:value-of select="@nodeName"/> </a> </li> </xsl:for-each> </xsl:template></xsl:stylesheet>
I hope someone will find this useful.
Maybe an admin want to check this thread as solved? :)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Highlight 'home' link in navigation
I've seen some examples in the forum but haven't gotten any of them to work with my xslt navigation.
This is what I have so far. As you can see the 'home' button is outside the loop and therefore not highlighted when clicked like the other pages. How can I incorporate the 'home' button into the navigation of the sub nodes?
I appreciate your help!
I'm sorry for beeing too hasty, I solved it myself. I added this line above template:
And added this before the for each loop:
This is the final code of my top navigation menu which highlights the home link:
I hope someone will find this useful.
Maybe an admin want to check this thread as solved? :)
is working on a reply...