I'm trying to make a 2 level sidebar menu with all the level 1 nodes showing, and only the level 2 nodes for the currently selected level 1 node shown. Like this
Another option is to look at this package which does exactly what you are looking for. You can either just use it or look at the XSLT to get a better idea on how to do it for yourself. It comes with example CSS as well showing you how you could style the nav.
2 level expanding navigation/menu
I'm trying to make a 2 level sidebar menu with all the level 1 nodes showing, and only the level 2 nodes for the currently selected level 1 node shown. Like this
Level 1-1
Level 1-2
Level 1-3
Level 2-1
Level 2-2
Level 1-4
Level 1-5
Where Level 1-3 would be "Currentpage"
Does anybody have some working XSLT for this?
Thanks
Mikael
Hi Mikael,
I'm sure you could have found some examples in this forum.... but here it goes:
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::node [@level = 1]/node">
<li><xsl-value-of select="@nodeName"/></li>
<xsl:if test="$currentPage/ancestor-or-self::node [@id = current()/@id]">
<ul>
<xsl:for-each select="current()/node">
<li><xsl-value-of select="@nodeName"/></li>
</xls:for-each>
</ul>
</xsl:for-each>
</ul>
Hope this helps (may have to add some more juice (a-tags, classes,...) - leaving this up to you)
Cheers,
/Dirk
Hi,
Another option is to look at this package which does exactly what you are looking for. You can either just use it or look at the XSLT to get a better idea on how to do it for yourself. It comes with example CSS as well showing you how you could style the nav.
T
Thanks - to both.
I fixed Dirks code with the missing </xsl:if> tag, but something is still wrong:
ul>
<xsl:for-each select="$currentPage/ancestor-or-self::node [@level = 1]/node">
<li>
<xsl-value-of select="@nodeName"/>
</li>
<xsl:if test="$currentPage/ancestor-or-self::node [@id = current()/@id]">
<ul>
<xsl:for-each select="current()/node">
<li>
<xsl-value-of select="@nodeName"/>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:for-each>
</ul
Umbraco won't save it and say that the (inner) xsl:for-each tag does not match it's /xsl:for-each tag, I pulled my hair on this one. Am i blind ?
Mikael
hmm, checked my code, i've made a minor mistake:
<xsl:for-each select="current()/node">
<li><xsl-value-of select="@nodeName"/></li>
</xls:for-each>
the end tag should be </XSL:for-each> instead of </XLS:for-each>
could that be the issue you're still facing?
cheers,
/Dirk
Thanks Dirk
that was just it
So i am blind (-:
Mikael
Just to help anyone looking at this post:
I added a check for the existence of any subnotes before the inner for-each. And som classes to use in the CSS for styling
This prevents the last node to be interpreted as level2 if the preceding node does not have any childnodes.
<ul class="Level1">
<xsl:for-each select="$currentPage/ancestor-or-self::node [@level = 2]/node">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
<xsl:if test="$currentPage/ancestor-or-self::node [@id = current()/@id] and count(current()/node) > 0">
<ul class="Level2">
<xsl:for-each select="current()/node">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:for-each>
</ul>
is working on a reply...