Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 363 posts 917 karma points
    Jan 14, 2013 @ 15:40
    Craig O'Mahony
    0

    List items contained within a content node

    Hi,

    I thought that this would be fairly simple but I'm struggling with it! What I am trying to do is build a menu up based upon the content items listed under a particular item of content. So in my content tree I have:

    Home (Root node)

    -FamilyHome (level 1)

    --Family About Us

    --Family Contact

    --Family How

    -RacingHome (level 1)

    --Racing About Us

    --Racing Contact 

    --Racing How

    I would have thought that I could use something like:

        <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::root" />
     <xsl:variable name="homeNode" select="$rootNode/home/familyHome [@isDoc]" />
     
    <!--loop through the root node and create the top level nav links-->
    <xsl:for-each select="$homeNode/* [@isDoc and @level = 3]">
    <li>
     <!--Test to see if this item is the current page if it is attached the selected class to the href-->
     <xsl:choose>
     
     <xsl:when test="$currentPage/self::* [@isDoc]/@id = current()/@id">
    <a class="current-menu-item" href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName" />
    </a>
     </xsl:when>
     
     <xsl:otherwise>
    <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName" />
    </a>  
     </xsl:otherwise>  
     </xsl:choose>
    </li>
    </xsl:for-each>

    But it's not finding anything? 

    Any ideas anyone?

    Thanks,

    Craig

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Jan 14, 2013 @ 15:48
    Chriztian Steinmeier
    100

    Hi Craig,

    Usually, the aliases are CamelCased (e.g. Home and FamilyHome) - did you specifically change them to use a lowercase initial letter?

    Also, you can shorten the XSLT a little like this:

    <xsl:for-each select="$homeNode/*[@isDoc]">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:if test="@id = $currentPage/@id"><xsl:attribute name="class">current-menu-item</xsl:attribute></xsl:if>
                <xsl:value-of select="@nodeName" />
            </a>
        </li>
    </xsl:for-each>

    /Chriztian

  • Craig O'Mahony 363 posts 917 karma points
    Jan 14, 2013 @ 17:12
    Craig O'Mahony
    0

    You my friend are an international superstar :) 

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Jan 14, 2013 @ 21:37
    Chriztian Steinmeier
    0

    Haha - thanks Craig :-)

  • 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