Copied to clipboard

Flag this post as spam?

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


  • Stephen 204 posts 246 karma points
    Aug 20, 2011 @ 16:56
    Stephen
    0

    Display sub nav menu only if there are sub nav items

    Hi There,

    My master template includes a right hand side are which is consistant thoughout all pages, with generic content. However if the user is on a page which has sub items I was to display a sub navaigaiton menu but ONLY if the page has sub menu items.

    I have the sub nav working and displaying but how do i "turn it off" for this sections with no sub content?

    TIA.

    Stephen

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Aug 20, 2011 @ 23:56
    Chriztian Steinmeier
    0

    Hi Stephen,

    Are you rendering the Subnav with an XSLT macro? Or maybe an inline Razor macro?

    /Chriztian 

  • Stephen 204 posts 246 karma points
    Aug 21, 2011 @ 09:08
    Stephen
    0

    I'm using one of the existing/built in XSLT macro's, new to XSLT and not even looked at Razor yet....

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 21, 2011 @ 13:48
    Fuji Kusaka
    0

    Hi Stephen,

    From what I understood is you have a generic menu which has child nodes but those nodes will only be displayed when clicking on the parent node right??

    Can you show up your content structure?

    //fuji

  • Stephen 204 posts 246 karma points
    Aug 21, 2011 @ 20:23
    Stephen
    0

    I'm not explaining myself well i know...

    So for instance my about page has no sub pages and my servivces page does.  They both use the same master page with the same righthand side content, in the that content i want to have a sub nav that would have a H3 title of "Section Menu", however if the page (i.e about) does not have any sub pages then i dont want that H3 title or sub nav to display. I know the sub nav WONT appear as umbraco will know there are no sub pages but what about the h3 tag and content?

    Or am i going about this in the wrong way?!

    Cheers,

    S

  • Tom Madden 253 posts 455 karma points MVP 4x c-trib
    Aug 21, 2011 @ 21:34
    Tom Madden
    0

    Stephen,

    what you need to do is to wrap your foreach loop in a test to see if there are any nodes to process. You can do this using the count() function like this:

    <xsl:if test="count(yourSelectStatement) &gt; 0">
        <xsl:for-each select="yourSelectStatement">
            <!-- your loop code here -->
        </xsl:for-each>
    </xsl:if>

    Basically, the first and last lines are added in the relevant place (you might call a template or generate a ul, so I can't be specific here (if you have a ul, your if statement should be outside the ul, so you don't have an empty ul created).

    You should copy your existing select statement (the bit where I've put "yourSelectStatement") and remeber to update the count line as well if you change your selecte statement in the future.

    HTH

    Tom

  • Stephen 204 posts 246 karma points
    Aug 21, 2011 @ 21:38
    Stephen
    0

    Thanks tom, i'll give this a go tomorrow, appreaciate the psot.

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 22, 2011 @ 05:03
    Fuji Kusaka
    0

    Hi Stephen you could loop and test whenever there are nodes that needs to be displayed when opening the parent nodes. 

    Basically here the Parent Nodes will always be available while the child nodes will be displayed when clicking on its relative parent.

    Here it will test if ever there are new nodes under the parent and if ever you have nodes it will call the template.

    <xsl:template match="/">
      <!-- start writing XSLT -->
     
         <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">          
               <li>
                 <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/></a>
              </li>
               <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id">  
                 <xsl:call-template name="drawNodes">  
                      <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=2]"/>                
                </xsl:call-template>
              </xsl:if>       
             </xsl:for-each>  
    </xsl:template>
            
      <xsl:template name="drawNodes">
        <xsl:param name="parent"/>   
        <xsl:if test="$parent/@level &lt; $maxLevel">
         
            <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1']">
              <li style="padding-left:10px;">    
                <a>
                 <xsl:attribute name="href"> <xsl:value-of select="umbraco.library:NiceUrl(@id)"/></xsl:attribute>
                 <xsl:value-of select="@nodeName"/>
                </a>            
              </li>
              <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) &gt; 0 and $currentPage/ancestor-or-self::*/@id = current()/@id">   
                  <xsl:call-template name="drawNodes">    
                    <xsl:with-param name="parent" select="."/>    
                  </xsl:call-template>  
                </xsl:if>
            </xsl:for-each>
          
        </xsl:if>
      </xsl:template>

     

    Hope it helps.

     

    //fuji

     


Please Sign in or register to post replies

Write your reply to:

Draft