Copied to clipboard

Flag this post as spam?

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


  • Lars Hesselberg 4 posts 24 karma points
    Jun 18, 2011 @ 18:51
    Lars Hesselberg
    0

    XSLT menu, listing subpages

    After several searches and trying out different solutions, I give up.

    I got a typical menu;

    - Main 1 (hardcoded)
    - Main 2
      ------ sub 1
      ------ sub 2
      ------ sub 3
    - Main 3
    - Main 4

    I've gotten it to show the Main and the sub menu fine, with the added class="selected" depending on what node you're on.

    My submenu however, dissapears whenever I enter one of the sub pages.

    My Content structure is as follows:

    Primary node, the frontpage (1)
      ------ Textpage (2)
      ------------ Textpage (3)
      ------------ Textpage (3)
      ------ Textpage (2)
      ------ Textpage (2)

    Here's the XSLT:

    <!-- Main menu -->
      <ul id="menu">
        <li>
          <href="/">
        <xsl:if test="$currentPage/@id = 1050">
          <xsl:attribute name="class">selected</xsl:attribute>
        </xsl:if>
          Forside      
          </a>
        </li>
      <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]/* [@isDoc and string(umbracoNaviHide) != '1']">
        <xsl:sort select="@sortOrder" order="ascending"/>
        <li|
          <href="{umbraco.library:NiceUrl(current()/@id)}">
          <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
            <xsl:attribute name="class">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="current()/@nodeName"/>
          </a>    
        </li>
      </xsl:for-each>
      </ul>
    <!-- Sub menu -->
      <xsl:if test="count($currentPage/* [@level=3]/*) &gt; 0">
      <ul id="subMenu">
      <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=2]/* [@isDoc and string(umbracoNaviHide) != '1']">
        <xsl:sort select="@sortOrder" order="ascending"/>
        <li<xsl:if test="position() != 1"</xsl:if>
          <href="{umbraco.library:NiceUrl(current()/@id)}">
          <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
            <xsl:attribute name="class">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="current()/@nodeName"/>
          </a>    
        </li>
      </xsl:for-each>
      </ul>
      </xsl:if>

    I also attempted doing the menu in Razor, but that went even worse, so I went with what I knew some of.

    // Lars

  • Lars Hesselberg 4 posts 24 karma points
    Jun 18, 2011 @ 18:54
    Lars Hesselberg
    0

    I believe the issue is the if statement before the subMenu starts, but I'm not quite sure.

  • Tom Fulton 2030 posts 4996 karma points c-trib
    Jun 18, 2011 @ 22:11
    Tom Fulton
    0

    Hi Lars,

    The issue does appear to be with that if statement.  It's checking to see if there are any subpages under the current page.  So when you are on a subpage - there won't be any pages under it.  Instead you should probably have it walk up the tree to level 2, and see if it has any subpages.  I think this should work:

    <xsl:if test="count($currentPage/ancestor-or-self::* [@isDoc][@level=2]/* [@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
      <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=2]/* [@isDoc and string(umbracoNaviHide) != '1']">

    Also just a quick note, you shouldn't need the <xsl:sort tag as it should sort the nodes by their order in Umbraco by default.

    -Tom

  • Lars Hesselberg 4 posts 24 karma points
    Jun 18, 2011 @ 23:54
    Lars Hesselberg
    0

    Aha! Yeah that makes sense, looking at what you wrote -- it also worked.

    Removed the sort too, you're right, there's no need for that.

  • 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