Copied to clipboard

Flag this post as spam?

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


  • Eddie Foreman 215 posts 288 karma points
    Dec 13, 2011 @ 18:50
    Eddie Foreman
    0

    Only show child node in current section

    Hi All,

    Been creating a menu, which is similiar to 'menu from changable source'.  Which starts in the current section and lists nodes from level 2 to 5.

    Site stucture is:

    - resources
      - pdfs
         - doc one
       - audio
       - ...

    I almost there and can replicate the above on each page.  But would like to only show the 'doc one' item when either on the 'pdfs' and 'doc one' pages.   

    My xslt is:

    <xsl:variable name="startNodeId">
    <xsl:choose>
    <xsl:when test="$currentPage/self::*/@level = '2'">
    <xsl:value-of select="$currentPage/self::*/@id"/>
    </xsl:when>
    <xsl:when test="$currentPage/self::*/@level = '3'">
    <xsl:value-of select="$currentPage/parent::*/@id"/>
    </xsl:when>
    <xsl:when test="$currentPage/self::*/@level = '4'">
    <xsl:value-of select="$currentPage/../parent::*/@id"/>
    </xsl:when>
    </xsl:choose>
    </xsl:variable>

    <xsl:template match="/">
    <ul>
    <li>
    <xsl:if test="$currentPage/self::*/@id = $startNodeId">
    <xsl:attribute name="class">active</xsl:attribute>
    </xsl:if>
    <a href="{umbraco.library:NiceUrl($startNodeId)}">
    <xsl:value-of select="umbraco.library:GetXmlNodeById($startNodeId)/@nodeName"/>
    </a>
    <xsl:call-template name="sub" />
    </li>
    </ul>
    </xsl:template>

    <xsl:template name="sub">
    <ul>
    <xsl:for-each select="umbraco.library:GetXmlNodeById($startNodeId)/* [@isDoc and string(umbracoNaviHide) != '1']">
    <li>
    <xsl:if test="$currentPage/ancestor-or-self::*/@id = @id">
    <xsl:attribute name="class">active</xsl:attribute>
    </xsl:if>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    <xsl:if test="./* [@isDoc and string(umbracoNaviHide) != '1']">
    <xsl:call-template name="level4"></xsl:call-template>
    </xsl:if>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

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

    Using Umbraco 4.7.1

    Thanks in advance,
    Eddie

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Dec 13, 2011 @ 20:09
    Jan Skovgaard
    0

    Hi Eddie

    At a glance I'm thinking that you should be able to achieve this by adding <xsl:if test="$currentPage/ancestor-or-self::pdfs"> or whatever the property of your pdf's document type is of course (It must of course also be unique of course otherwise if it's just a generic textpage like the rest it will go all the way to level 1) :)

    /Jan

  • Eddie Foreman 215 posts 288 karma points
    Dec 13, 2011 @ 22:23
    Eddie Foreman
    0

    Hi Jan,

    Thanks for the ideal.  The above stucture is just one section of the site.  The menu will be used across the site and so would need to work across mutiple doucments types. One thought I had was to check the child parent id of the current page on level 4 nodes and if this matched, then use this to control when the level 5 nodes are displayed.  And when on level 5 nodes, check the parent page id - level 4 - against the parent id of the child page to display the child nodes.  In theory I think it should work, although I've not yet managed it in the xslt.

    Eddie

  • Eddie Foreman 215 posts 288 karma points
    Dec 13, 2011 @ 23:39
    Eddie Foreman
    0

    Hi Jan,

    All working now, wrapped an if statement around the call to the level4 template.

    <xsl:if test="$currentPage/self::*/@id = ./*/@parentID">
      <xsl:call-template name="level4"></xsl:call-template>
    </xsl:if>

    Thanks,
    Eddie

Please Sign in or register to post replies

Write your reply to:

Draft