Copied to clipboard

Flag this post as spam?

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

  • Robert Valcourt 70 posts 103 karma points
    Aug 10, 2015 @ 20:04
    Robert Valcourt

    Disable subnav when at certain node tree

    I have a subnav XSLT script that displays all child nodes of the tree currently being viewed. This works fine. I want to 'disable' the subnav when you are viewing a certain node tree by its @id.

    For example if you are viewing:, all of the child nodes display in the sidebar., all of the child nodes display in the sidebar., subnav display should be disabled. has a node @id of 1148. Whether you are viewing this node or any of its children nodes, no subnav should be displayed.

    The script basically works like this:

    <xsl:variable name="level" select="2"/>
    <xsl:variable name="mainNodes" select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']"/>
    <xsl:for-each select="$mainNodes">
    // Do something

    The way I see it, an IF statement needs to be put above the xsl:for-each

    <xsl:if node being viewed or any child of 1148 is not true>
      <xsl:for-each select="$mainNodes">
        // Do something

    I can't seem to get the syntax right. Thoughts?

  • Per Olsson 47 posts 307 karma points
    Aug 11, 2015 @ 06:27
    Per Olsson

    I would not recommend to hardcode the page ID, instead make a checkbox property on the documenttype and set it where you want to hide it.

    You should be able to modify "mainNodes" variable by simply adding the following to your select (or whatever propertyname you choose):

    and not(hideSubnav = 1) 
  • Robert Valcourt 70 posts 103 karma points
    Aug 11, 2015 @ 08:38
    Robert Valcourt

    @Per Olsson your example will not work for me. That checks against the single node being viewed, im trying to hide an entire node tree. Basically, if you are viewing node 1148 or ANY child of, simply don't process the subnav script period.

  • Chriztian Steinmeier 2750 posts 8456 karma points MVP 6x admin c-trib
    Aug 14, 2015 @ 22:06
    Chriztian Steinmeier

    Hi Robert,

    You're actually on the right track, but the XSLT syntax you're using is for the legacy schema, which you're probably not using (Umbraco 4.1 or below, IIRC).

    Here's a chunk of code that outlines how I'd approach a similar situation - note that it handles both the "hardcoded ID" scenario you're suggesting and the hideSubnav property that Per suggested:

    <?xml version="1.0" encoding="utf-8" ?>
        <xsl:output method="html" indent="yes" omit-xml-declaration="yes" />
        <xsl:param name="currentPage" />
        <xsl:variable name="level" select="2" />
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = $level]" />
        <xsl:variable name="mainNodes" select="$siteRoot/*[@isDoc][not(umbracoNaviHide = 1)]" />
        <xsl:template match="/">
                <xsl:apply-templates select="$mainNodes" />
        <!-- General template for a node -->
        <xsl:template match="*[@isDoc]">
            <xsl:variable name="subNodes" select="*[@isDoc][not(umbracoNaviHide = 1)]" />
                <a href="{umb:NiceUrl(@id)}"><xsl:value-of select="@nodeName" /></a>
                <xsl:if test="$subNodes">
                        <xsl:apply-templates select="$subNodes" />
        <!-- Template for a specific node that shouldn't be processed -->
        <xsl:template match="*[@id = 1148] | *[hideSubnav = 1]" priority="1">
            <!-- Do nothing -->

    Hope that helps,


Please Sign in or register to post replies

Write your reply to: