Copied to clipboard

Flag this post as spam?

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


  • adam 14 posts 74 karma points
    Apr 28, 2013 @ 22:11
    adam
    0

    Displaying pages/ subpage links in xslt

    I am trying to list all pages/subpages of the parent page in a sidebar, this is what I have at the moment:


    <xsl:param name="currentPage"/>
    <xsl:template match="/">

    <!-- The fun starts here -->
    <aside>  
        <ul>
            <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=2]">  
            <li>
              <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
            </li>
          </xsl:for-each>


            <xsl:for-each select="$currentPage/descendant::* [@isDoc and string(umbracoNaviHide) = '1']">
                <li>
                    <a href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:value-of select="@nodeName"/>
                    </a>
                </li>
            </xsl:for-each>
        </ul>
    </aside>

    This works fine and displays all the page links but I need to style/indent the parent page links

    The structure of the page/ links is setup like below

    Parent page

      > Page 1
      > Page 2
          > Sub page
          > Sub page
          > Sub page

      > Page 3

    But at the moment all the links regardless of whether they are a parent page or sub page are just rendered out in the li tags, so I cant style/indent the parent pages

    Hopefully that makes sense :o

    Does anyone know how I can change the xslt to do this please?

    Thanks!

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Apr 29, 2013 @ 00:11
    Chriztian Steinmeier
    0

    Hi Adam,

    Here's the standard XSLT way of doing stuff like that:

    <xsl:param name="currentPage" />
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
    <xsl:template match="/">
        <aside>
            <ul>
                <!-- Process all the child pages of the root -->
                <xsl:apply-templates select="$siteRoot/*[@isDoc][not(umbracoNaviHide = 1)]" />
            </ul>
        </aside>
    </xsl:template>
    
    <!-- Template for individual pages -->
    <xsl:template match="*[@isDoc]">
        <xsl:variable name="subPages" select="*[@isDoc][not(umbracoNaviHide = 1)]" />
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName" />
            </a>
    
            <!-- Process child pages (if any) -->
            <xsl:if test="$subPages">
                <ul>
                    <xsl:apply-templates select="$subPages" />
                </ul>
            </xsl:if>
        </li>
    </xsl:template>

    It uses a single template to render the links, which will automatically process any child pages, wrapping them in a nested <ul> for styling.

    Hope this helps,

    /Chriztian

  • adam 14 posts 74 karma points
    Apr 29, 2013 @ 12:19
    adam
    0

    Hey Chriztian

    Thanks for the reply!

    One problem - it's listing all the site pages, I just want to list all the pages from the parent page. Kind of like the below:

    > Parent page

         > Page 1
         > Page 2
             > Sub page
             > Sub page
             > Sub page

         > Page 3

    I tried changing a few things in your xslt above but can't seem to get it working :(, I presume its something to do with changing siteroot to currentpage or?

    On a side note would the sub nav still display all the links if you went into a child page for example?

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft