Copied to clipboard

Flag this post as spam?

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


  • Sebastian Dammark 583 posts 1407 karma points
    Mar 16, 2011 @ 10:32
    Sebastian Dammark
    0

    Expandable left navigation

    I have 2 problems with this navigation ...

    For some reason it shows the children to the item called 'Service menu' (id=1097) even though that umbracoNaviHide is set to 1, and all my selects include not(umbracoNaviHide = 1)

    The other problem, is that, I only want the navigation to expand along the way, showing subpages the pages I've clicked.

    Any ideas ?

    The XML looks like this.
    The XSLT has been hijacked from here and modified a bit so it now looks like this.

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:umb="urn:umbraco.library"
            exclude-result-prefixes="umb"
    >
    
            <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
            <xsl:param name="currentPage" />
            <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::Frontpage[@level = 1]" />
    
            <xsl:template match="/">
                    <ul class="leftnavigation">
                        <!-- Start with children of the site root -->
                        <xsl:apply-templates select="$siteRoot/Subpage/Subpage[@isDoc and not(umbracoNaviHide = 1)]" />
                    </ul>
            </xsl:template>
    
            <xsl:template match="Subpage[@isDoc]">
                    <xsl:variable name="firstitem" select="'first '" />
                    <xsl:variable name="lastitem" select="'last '" />
                    <xsl:variable name="currentitem" select="'selected '" />
    
                    <xsl:variable name="classes">
                        <xsl:if test="position() = 1">
                            <xsl:value-of select="$firstitem"/>
                        </xsl:if>
                        <xsl:if test="position() = last()">
                            <xsl:value-of select="$lastitem"/>
                        </xsl:if>
                        <xsl:if test="@id = $currentPage/@id">
                            <xsl:value-of select="$currentitem"/>
                        </xsl:if>
                    </xsl:variable>
                    <li>
                        <xsl:if test="normalize-space($classes)">
                            <xsl:attribute name="class">
                                <xsl:value-of select="normalize-space($classes)" />
                            </xsl:attribute>
                        </xsl:if>
                        <a href="{umb:NiceUrl(@id)}">
                            <xsl:if test="$currentPage/ancestor-or-self::Subpage[@id = current()/@id]">
                                <xsl:attribute name="class">aktiv</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="@nodeName" />
                        </a>
                        <!-- Make sure there is at least one visible page below, otherwise we get an empty <ul/> -->
                        <!-- If you need to stop at some level, do that here, like this: -->
                        <!-- <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)][not(level &gt; 4)]"> -->
                        <xsl:if test="Subpage[@isDoc and not(umbracoNaviHide = 1)]">
                            <ul>
                                <xsl:apply-templates select="Subpage[@isDoc and not(umbracoNaviHide = 1)]" />
                            </ul>
                        </xsl:if>
                    </li>
            </xsl:template>
    
            <!-- This automatically hides items with umbracoNaviHide checked -->
            <xsl:template match="Subpage[umbracoNaviHide = 1]" />
    
    </xsl:stylesheet>
  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Mar 16, 2011 @ 10:50
    Scott Hugh Alexandar Petersen
    0

    excerpt

    <!-- Make sure there is at least one visible page below, otherwise we get an empty <ul/> -->
    <!-- If you need to stop at some level, do that here, like this: -->
    <!-- <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)][not(level &gt; 4)]"> -->
    <xsl:if test="Subpage[@isDoc and not(umbracoNaviHide = 1)]">
    <ul> <!-- here you do a check for $currentPage/ancestor-or-self::Subpage/@id = @id --> <xsl:if test="$currentPage/ancestor-or-self::Subpage/@id = @id"> <!-- sorry I have taken this off the top of mind --> <xsl:apply-templates select="Subpage[@isDoc and not(umbracoNaviHide = 1)]" /> </xsl:if> </ul> </xsl:if>

    scott

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 16, 2011 @ 10:51
    Chriztian Steinmeier
    0

    Hi Sebastian,

    The reason it shows the items below "Service menu" is because your select skips the umbracoNaviHide test on that level - compare:

    <xsl:apply-templates select="$siteRoot/Subpage/Subpage[@isDoc and not(umbracoNaviHide = 1)]" />

    To this:

    <xsl:apply-templates select="$siteRoot/Subpage[not(umbracoNaviHide = 1)]/Subpage[@isDoc and not(umbracoNaviHide = 1)]" />
    

    /Chriztian 

  • Sebastian Dammark 583 posts 1407 karma points
    Mar 16, 2011 @ 11:02
    Sebastian Dammark
    0

    Thanx guys

Please Sign in or register to post replies

Write your reply to:

Draft