Copied to clipboard

Flag this post as spam?

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


  • trfletch 595 posts 571 karma points
    Dec 16, 2009 @ 11:53
    trfletch
    0

    Exclude page from menu based on document type

    Hi,

    I have an Umbraco V4 website which has a menu that I want to exclude certain document types from, I have tried the following, the bit in bold and underlined is the bit I have added but I don't think I have done this correctly because it is not working, can an XSLT expert give me some help?

    <xsl:variable name="maxLevelForSitemap" select="3"/>
    <xsl:template match="/">
    <div id="sitemap">
    <ul class="sf-menu sf-menu-home">
    <li><xsl:if test="$currentPage/@id = 1053">
    <xsl:attribute name="class">active-menu</xsl:attribute>
    </xsl:if><a href="/">Home</a></li>
    </ul>
    <xsl:call-template name="drawNodes"> 
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/> 
    </xsl:call-template>
    </div>
    </xsl:template>
    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
    <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
    <ul class="sf-menu"><xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]">
    <li><xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
      <xsl:attribute name="class">active-menu</xsl:attribute>
      </xsl:if>
    <xsl:choose>
    <xsl:when test="data [@alias = 'nomenulink'] ='1'">
    <a href="#">
    <xsl:value-of select="@nodeName"/></a>
    </xsl:when>
    <xsl:otherwise>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/></a>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="count(./node [string(./data [@alias='nestedmenuHide']) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0 and @nodeTypeAlias != 'NewsArticle'">  
    <xsl:call-template name="drawNodes">   
    <xsl:with-param name="parent" select="."/>   
    </xsl:call-template> 
    </xsl:if>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>
  • dandrayne 1138 posts 2262 karma points
    Dec 16, 2009 @ 17:02
    dandrayne
    0

    Hi There

    Here's an example for the business website started pack, adapted from similar code to yours (sitemap.xslt, probably)

    <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap and @nodeTypeAlias!='NewsItem' and @nodeTypeAlias!='Event' and @nodeTypeAlias!='DateFolder']"> 

    This would seem to fit right into your for-each above.

    Dan

  • dandrayne 1138 posts 2262 karma points
    Dec 16, 2009 @ 17:12
    dandrayne
    0

    I had the ocd-esque urge to indent your code, and came across a potential problem in the if-else around the call-template.  Basically you want to count and make sure no news articles are included in the count - try the following code (untested)

    <xsl:variable name="maxLevelForSitemap" select="3"/>
    <xsl:template match="/">
    <div id="sitemap">
    <ul class="sf-menu sf-menu-home">
    <li>
    <xsl:if test="$currentPage/@id = 1053">
    <xsl:attribute name="class">active-menu</xsl:attribute>
    </xsl:if>
    <a href="/">Home</a>
    </li>
    </ul>
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/>
    </xsl:call-template>
    </div>
    </xsl:template>


    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
    <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
    <ul class="sf-menu">
    <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]">
    <li>
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <xsl:attribute name="class">active-menu</xsl:attribute>
    </xsl:if>

    <xsl:choose>
    <xsl:when test="data [@alias = 'nomenulink'] ='1'">
    <a href="#">
    <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:when>
    <xsl:otherwise>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    </xsl:otherwise>
    </xsl:choose>

    <xsl:if test="count(./node [string(./data [@alias='nestedmenuHide']) != '1' and @level &lt;= $maxLevelForSitemap and @nodeTypeAlias != 'NewsArticle']) &gt; 0">
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="."/>
    </xsl:call-template>
    </xsl:if>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>

    Dan

  • trfletch 595 posts 571 karma points
    Dec 16, 2009 @ 17:45
    trfletch
    0

    Thanks Dan,

    That has worked perfectly. I know what I wanted to do and pretty much how I wanted to do it I just didn't know the correct syntax to make it happen!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies