We're trying to have a top-level menu navigation package work as follows. The top menu will show only Level = 2 nodes, which it is doing properly.
On each page however, we have multiple levels of nested content. So for example, we have a site structure that looks like this:
Our People (shown in top nav) - Lawyer 1 (shown on page left menu only) - Lawyer 2 ^
When we're displaying the "Our People" in the top nav, we want to show that menu item as selected. We currently have the following XSLT for displaying the top navigation and we're using ancestor-or-self to check if the $currentPage is a child of the current() top nav item. This is the part that is not working. We cannot get the current class to display on "Our People" when on the Lawyer 1, 2 pages.
<xsl:for-each select="$currentPage/ancestor-or-self::node/node [@level = 2 and string(data[@alias='umbracoNaviHide']) != '1']"> <li> <!-- Add the class selected if the currentpage or parent nodes (up the tree to the root) ID matches our current node ID in the for each loop --> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <xsl:attribute name="class"> <xsl:text>current</xsl:text> </xsl:attribute> </xsl:if>
I had tried that, but it also does not work. It works for showing the $currentPage as selected, but not the parent of the $currentPage in my top navigation.
ancestor or self - is this not proper?
We're trying to have a top-level menu navigation package work as follows. The top menu will show only Level = 2 nodes, which it is doing properly.
On each page however, we have multiple levels of nested content. So for example, we have a site structure that looks like this:
Our People (shown in top nav)
- Lawyer 1 (shown on page left menu only)
- Lawyer 2 ^
When we're displaying the "Our People" in the top nav, we want to show that menu item as selected. We currently have the following XSLT for displaying the top navigation and we're using ancestor-or-self to check if the $currentPage is a child of the current() top nav item. This is the part that is not working. We cannot get the current class to display on "Our People" when on the Lawyer 1, 2 pages.
<xsl:for-each select="$currentPage/ancestor-or-self::node/node [@level = 2 and string(data[@alias='umbracoNaviHide']) != '1']">
<li>
<!--
Add the class selected if the currentpage or parent nodes (up the tree to the root)
ID matches our current node ID in the for each loop
-->
<xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
<xsl:attribute name="class">
<xsl:text>current</xsl:text>
</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="current()/@nodeName" />
</a>
</li>
</xsl:for-each>
This is the xslt im using in our menu xslt,
<xsl:if test="$currentPage/ancestor-or-self::node/@id=@id">
<xsl:attribute name="class">inpath</xsl:attribute>
</xsl:if>
<xsl:if test="$currentPage/@id=@id">
<xsl:attribute name="class">selected</xsl:attribute>
</xsl:if>
<xsl:if test="$currentPage/ancestor-or-self::node/@id=@id and $currentPage/@id=@id">
<xsl:attribute name="class">inpath selected</xsl:attribute>
</xsl:if>
I had tried that, but it also does not work. It works for showing the $currentPage as selected, but not the parent of the $currentPage in my top navigation.
Hi Matt,
What you have there looks like it should work. Looks like you'll have to do some debugging to see where the problem lies.
Try putting some output into your XSLT to see if the values are aas expected or if something funky is going on e.g.
<xsl:value-of select="current()/@id" />
is working on a reply...