Developer forum

Forum » Templates » Navigation: When reached endlevel - show currentlevel pages

Navigation: When reached endlevel - show currentlevel pages

Lars Pham
Reply

Hi.. 

I have a sitemap looking like this:

Page A
  - Subpage A1
     - Sub-subpage A1
     - Sub-subpage A2
  - Subpage A2
Page B
 - Etc.

Now I have a left sidebar navigation that only show the current page's children.

For example when I'm in Page A - I only get "Subpage A1" and "Subpage A2". If I go deeper in - into "Subpage A1" - I get the next level subpages "Sub-subpage A1" and "Sub-subpage A2". Which works nicely. 

I would like to when I reach an endlevel - in this case the "Sub-subpage" level - which has no children to just show the current level in the navigation. 

Hope it made sense - is this possible? 

Here's my current xslt:

<?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">
      <div class="menu row">
        <xsl:apply-templates select="Page" mode="subpage" />
      </div>
    </xsl:if>
  </xsl:template>


  <xsl:template match="Page" mode="subpage">
    <xsl:variable name="AbsoluteDepth" select="@AbsoluteLevel"/>
    <div class="col-lg-12 col-md-12 col-sm-6 col-xs-12">
        <a>
            <xsl:variable name="NavigationImage">
                <xsl:choose>
                    <xsl:when test="@Image!=''">
                        <xsl:value-of select="@Image"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="/NavigationTree/Settings/Setting[@Level=$AbsoluteDepth]/NavigationImage/@Value"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <xsl:variable name="NavigationMouseoverImage">
                <xsl:choose>
                    <xsl:when test="@ImageMouseOver!=''">
                        <xsl:value-of select="@ImageMouseOver"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="/NavigationTree/Settings/Setting[@Level=$AbsoluteDepth]/NavigationMouseoverImage/@Value"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <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:attribute name="href">
                <xsl:value-of select="@FriendlyHref" />
            </xsl:attribute>
            <div class="submenu">
                <xsl:if test="@Active='True'">
                    <xsl:attribute name="id">activeitem</xsl:attribute>
                </xsl:if>      
                <xsl:if test="$NavigationImage=''">
                    <xsl:attribute name="class">submenu noImg</xsl:attribute>
                </xsl:if>    
                <h3><xsl:value-of select="@MenuText" /></h3>
                <xsl:if test="$NavigationImage!=''">
                    <img src="{$NavigationImage}" name="img{@ID}" border="0" alt="{@MenuText}" align="absmiddle" /> 
                </xsl:if>
                <span class="overlay" >
                    <xsl:if test="$NavigationMouseoverImage!=''">
                        <xsl:attribute name="style">
                            <xsl:value-of select="concat('background: url(',$NavigationMouseoverImage,') repeat;')" />
                        </xsl:attribute>
                    </xsl:if>
                </span>    
            </div>
        </a>
    </div>
  </xsl:template>
</xsl:stylesheet> 


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Lars

In your apply statement, do something like this:

<xsl:choose>
 <xsl:when test="count(//Page[@Active='True']) > 0">
  <xsl:apply-templates select="//Page[@Active='True']/Page"></xsl:apply-templates>
 </xsl:when>
 <xsl:otherwise>
  <xsl:apply-templates select="//Page[@Active='True']/parent::Page"></xsl:apply-templates>
 </xsl:otherwise>
</xsl:choose>

 
Lars Pham
Reply

Hi Nicolai,

Do you mean adding that instead of: 

<xsl:template match="/NavigationTree">
    <xsl:apply-templates select="//Page[@Active='True']"></xsl:apply-templates>
</xsl:template> 

 
Nicolai Høeg Pedersen
Reply

Yes!

 
Lars Pham
Reply

Hmm.. Still doesn't work..

Do I need to set a setting where i declare the navigation? 

This is my HTML: "<div class="dwnavigation" title="Venstre navigation" id="LeftNavigationw" settings="template:LICleanSub.xslt;"></div>"

 

 

 
Nicolai Høeg Pedersen
Reply

Hi Lars

Yes, please read the Designs & Layout documentation, chapter 3.2. Set expandmode:all

BR Nicolai

 

You must be logged in to post in the forum