Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mikael Mørup 297 posts 326 karma points
    Aug 20, 2009 @ 08:59
    Mikael Mørup
    0

    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
       

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Aug 20, 2009 @ 09:15
    Dirk De Grave
    1

    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

  • Tim 225 posts 690 karma points
    Aug 20, 2009 @ 10:34
    Tim
    2

    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

  • Mikael Mørup 297 posts 326 karma points
    Aug 20, 2009 @ 13:38
    Mikael Mørup
    0

    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

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Aug 20, 2009 @ 14:00
    Dirk De Grave
    100

    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

     

  • Mikael Mørup 297 posts 326 karma points
    Aug 20, 2009 @ 14:05
    Mikael Mørup
    0

    Thanks Dirk

    that was just it

     

    So i am blind  (-:

    Mikael

  • Mikael Mørup 297 posts 326 karma points
    Aug 21, 2009 @ 08:29
    Mikael Mørup
    0

    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>

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies