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?
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??
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?
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) > 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.
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
Hi Stephen,
Are you rendering the Subnav with an XSLT macro? Or maybe an inline Razor macro?
/Chriztian
I'm using one of the existing/built in XSLT macro's, new to XSLT and not even looked at Razor yet....
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
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
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:
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
Thanks tom, i'll give this a go tomorrow, appreaciate the psot.
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.
Hope it helps.
//fuji
is working on a reply...