I'm using the topnavigation macro for my navigation, and i wan't to put class="active" on the link which you are currently looking at.
So if you are at information.aspx then in the navigation the information.aspx link shall have class="active" but the other links in the navigation shall not have class="active" - how to do that? I've been playing around with it and I can only get it to either all have class="active" or none...
<!--This sets the level that the nav starts at and tells us if we should recurse through child elements--> <xsl:variable name="startDepth" select="/macro/startingLevel" /> <xsl:variable name="recurse" select="/macro/recurse" /> <xsl:variable name="selectBranches" select="/macro/selectBranches"></xsl:variable> <xsl:variable name="maxMenuDepth" select="/macro/maxMenuDepth"></xsl:variable> <xsl:variable name="forceNode" select="/macro/forceNode"></xsl:variable> <xsl:variable name="walkChildren" select="/macro/expandChildren"></xsl:variable> <xsl:variable name="forceHome" select="/macro/forceHome"></xsl:variable> <xsl:variable name="subNav" select="/macro/subNav"></xsl:variable> <!--Alternate page title variable in here-->
<!--Styles for the navigation--> <xsl:variable name="ulBaseClass" select="/macro/ulBaseClass"></xsl:variable> <xsl:variable name="branchClass" select="/macro/branchClass"></xsl:variable> <xsl:variable name="selectedClass" select="/macro/selectedClass"></xsl:variable>
<!--Set the current node id i.e. the node we have looped to not the current page--> <xsl:variable name="currentNodeID" select="./@id" />
<!--Is the node a branch? i.e. are there children and is it in the colletion of ancestor nodes --> <xsl:variable name="isBranch"> <xsl:choose> <xsl:when test="$pseudoCurrentPage/ancestor-or-self::node[@id = $currentNodeID]/child::node">1</xsl:when> </xsl:choose> </xsl:variable>
<!--Is the node selected? i.e. is it the same as the currentPage node--> <xsl:variable name="isSelected"> <xsl:choose> <xsl:when test="$pseudoCurrentPage/@id = $currentNodeID">1</xsl:when> </xsl:choose> </xsl:variable>
Can't you use the stuff from the "Navigation prototype" XSLT?
<a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <!-- we're under the item - you can do your own styling here --> <xsl:attribute name="style">font-weight: bold;</xsl:attribute> </xsl:if> <xsl:value-of select="@nodeName"/> </a>
Then instead of adding the style attribute just write <xsl:attribute name="class">active</xsl:attribute>
TopNavigation problem
I'm using the topnavigation macro for my navigation, and i wan't to put class="active" on the link which you are currently looking at.
So if you are at information.aspx then in the navigation the information.aspx link shall have class="active" but the other links in the navigation shall not have class="active" - how to do that? I've been playing around with it and I can only get it to either all have class="active" or none...
hey,
i attached the xslt that i'm using for top navigation, that take care for the "active" page (look for the "selectedClass" variable).
Eran.
Hi Daniel
Can't you use the stuff from the "Navigation prototype" XSLT?
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
<!-- we're under the item - you can do your own styling here -->
<xsl:attribute name="style">font-weight: bold;</xsl:attribute>
</xsl:if>
<xsl:value-of select="@nodeName"/>
</a>
Then instead of adding the style attribute just write <xsl:attribute name="class">active</xsl:attribute>
/Jan
Here you go: (Just change "current" to whatever you'd like)
Thanks, it worked..
Doesn't really understand why my own doesn't, but nevermind - thanks for the help guys :)
please mark this question as resolved
is working on a reply...