Developer forum

Forum » Templates » Navigation - list subpages from current page

Navigation - list subpages from current page

Kim Rasmussen
Reply

Hi Forum,

This should be very simple - but apparently it isn't.

- Current page
---- Sub page 
---- Sub page

- Sibling
---- Sub page
- Sibling

My goal is to only show the two sub pages located under the current page.

I tried with this, in my template:

<ul class="dwnavigation" id="SubNavigation" settings="startlevel:1;parentid:<!--@DwPageID-->;template:LIClean.html;expandmode:none;" >

But DW does not parse <!--@DwPageID--> and shows the pages on start level 1 (default behaviour).

Best regards
Kim


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Kim

 

Navigations are inserted before the template tags are parsed, so you cannot use template tags in your navigation settings.

 

Basically you should just set startlevel to 2, endlevel to 2 and remove all your other settings, and you get what you want.

 

BR Nicolai

 
Kim Rasmussen
Reply

Hi Nicolai,

Thank you very much for your answer.

Maybe I wasn't clear enough, but the current page could be on any level. I want to avoid making templates for level 1 pages, level 2 pages and so on :)

The 'startlevel:1'-part is just the default value. 

Best regards
Kim

 
Nicolai Høeg Pedersen
Reply

Hi Kim

 

Then just remove startlevel and endlevel settings, make a copy of liclean.xslt to use and remove the recursive call from that:

 

That would be this part to remove:

 

<xsl:if test="count(Page)">
          <ul class="M{@AbsoluteLevel}">
            <xsl:apply-templates select="Page">
              <xsl:with-param name="depth" select="$depth+1"/>
            </xsl:apply-templates>
          </ul>
        </xsl:if>
 
Kim Rasmussen
Reply

Hi Nicolai,

DW still outputs level 1 pages :(

Template:

<ul class="dwnavigation" id="SubNavigation" settings="template:LICleanMobile.html;expandmode:none;" >

 

XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

  <!--
  Description: ul/li based navigation. No features from admin implemented.
  Recommended settings:
  Fold out: True or False
  Upper menu: Dynamic or Static
  First level: > 0
  Last level: >= First level
  -->
  
  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"  encoding="utf-8" />
  <xsl:param name="html-content-type" />
  <xsl:template match="/NavigationTree">
    
    <xsl:if test="count(//Page) > 0">
    	
      <ul class="menu">
        <xsl:apply-templates select="Page">
          <xsl:with-param name="depth" select="1"/>
        </xsl:apply-templates>
      </ul>
    </xsl:if>

  </xsl:template>

  <xsl:template match="//Page">
    <xsl:param name="depth"/>
    <li>
      <a>
      	<xsl:attribute name="class">
        <xsl:if test="position() = 1">firstitem </xsl:if>
        <xsl:if test="position() = count(//Page)">lastitem </xsl:if>
        <xsl:if test="@InPath='True'">inpath</xsl:if>
        </xsl:attribute>
        <xsl:if test="@Active='True'">
          <xsl:attribute name="id">activeitem</xsl:attribute>
        </xsl:if>
        <xsl:attribute name="href"><xsl:value-of select="@FriendlyHref" disable-output-escaping="yes"/></xsl:attribute>
        <xsl:value-of select="@MenuText" disable-output-escaping="yes"/>
        <i class="icon-chevron-right"><xsl:text> </xsl:text></i>
      </a>

    </li>
  </xsl:template>

</xsl:stylesheet>

 

 
Nicolai Høeg Pedersen
Reply

Remove expandmode:none...

 
Morten Bengtson
Reply
This post has been marked as an answer

Or you can modify the XSLT to find the current page (@Active='True') and only render its sub-pages like this...

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" encoding="utf-8" />
  
  <xsl:template match="/NavigationTree">
    <xsl:apply-templates select="//Page[@Active='True']"></xsl:apply-templates>
  </xsl:template>

  <xsl:template match="Page">
    <xsl:if test="count(Page) > 0">
      <ul class="menu">
        <xsl:apply-templates select="Page" mode="subpage" />
      </ul>
    </xsl:if>
  </xsl:template>

  <xsl:template match="Page" mode="subpage">
    <li>
      <a>
        <xsl:attribute name="class">
          <xsl:if test="position() = 1">firstitem </xsl:if>
          <xsl:if test="position() = count(//Page)">lastitem </xsl:if>
          <xsl:if test="@InPath='True'">inpath</xsl:if>
        </xsl:attribute>
        <xsl:if test="@Active='True'">
          <xsl:attribute name="id">activeitem</xsl:attribute>
        </xsl:if>
        <xsl:attribute name="href">
          <xsl:value-of select="@FriendlyHref" />
        </xsl:attribute>
        <xsl:value-of select="@MenuText" />
      </a>
    </li>
  </xsl:template>

</xsl:stylesheet>

 

Votes for this answer: 1
 
Kim Rasmussen
Reply

Thanks Morten,

Now it works!

 
Hans Ravnsfjall
Reply

Exactly what I need as well. Thanx Morten :)

 

 

You must be logged in to post in the forum