I'm still new to Umbraco and don't fully understand XSLT yet, so I'm having trouble getting my sub-navigation working.
I have my sub-navigation working in a single level, but I want to be able to drill down another level when needed. I basically want to be able to add a <ul class="lv2"> HTML tag within my current <ul class="lv1"> tag and then style that with CSS so it looks like a sub level of the currently selected level.
To better explain, my sub-navigation looks like this:
Some Topic Another Topic Third Topic
But when "Another Topic" is selected, I want it to look like is:
Some Topic Another Topic Something Here Another Something Third topic
I know how to do this in HTML and CSS, I'm just not sure how to get there in XLST. Here is my current SubNavigation.xlst file:
The above code actually works when I'm viewing a 2nd level page. If a second level page is selected and it has 3rd level children below it, all of those child links show in the navigation. Works perfect right... just how I want it to. However, once I click on one of those 3rd level links, the navigation goes back to only showing 2 levels (when I want it to keep showing 3 levels). I would like to have my second level marked with class="selected", and also do the same for the third level. The problem is, the third level no longer shows.
I know why this is happening. It's because I'm using that XSL IF statement. When I am on a third level page and this SubNavigation.xslt file is called, it finds my if statement and says there are no children. Therefor, no 3rd level pages are being shown.
I think I finally have this working. I downloaded some demo Umbraco sites and found a Koiak Standard Site that did the sub-navigation similar to what I wanted. I took their two lines of IF statements and modified it to suite my needs. This is the code I ended up with:
Question though... is that the best way to do this? It appears to be working perfectly... but I'm not sure if there's a better way to be doing it. The two lines of code from the Koiak demo site that got this working for me were:
What the above code does is of course to render a submenu. In the top of the menu, there's a link to the "main-menu-page". Of course this can be removed easily. The code will continue to add additional levels of nodes if they are present in the content tree.
I don't know if this can inspire you, but now you've got the code for a quite easy submenu macro. Take it or leave it :)
Need help with sub-navigation XSLT
Hey everyone,
I'm still new to Umbraco and don't fully understand XSLT yet, so I'm having trouble getting my sub-navigation working.
I have my sub-navigation working in a single level, but I want to be able to drill down another level when needed. I basically want to be able to add a <ul class="lv2"> HTML tag within my current <ul class="lv1"> tag and then style that with CSS so it looks like a sub level of the currently selected level.
To better explain, my sub-navigation looks like this:
Some Topic
Another Topic
Third Topic
But when "Another Topic" is selected, I want it to look like is:
Some Topic
Another Topic
Something Here
Another Something
Third topic
I know how to do this in HTML and CSS, I'm just not sure how to get there in XLST. Here is my current SubNavigation.xlst file:
I know the code I have to insert needs to go towards the end of that XSLT file before the following:
I've been playing around with this for a while now and I have the following code working:
The above code actually works when I'm viewing a 2nd level page. If a second level page is selected and it has 3rd level children below it, all of those child links show in the navigation. Works perfect right... just how I want it to. However, once I click on one of those 3rd level links, the navigation goes back to only showing 2 levels (when I want it to keep showing 3 levels). I would like to have my second level marked with class="selected", and also do the same for the third level. The problem is, the third level no longer shows.
I know why this is happening. It's because I'm using that XSL IF statement. When I am on a third level page and this SubNavigation.xslt file is called, it finds my if statement and says there are no children. Therefor, no 3rd level pages are being shown.
I probably just need one line of code to get this working... but I'm not sure what I can try. Can someone help point me in the right direction?
Check if the current page equal to the navigation item
<xsl:for-each .... >
<xsl:if test="$currentPage/@id = current()/@id>
... show sub navigation ...
</xsl:if>
</xsl:for-each>
Nevermind.. didn't read the entire post.
Sorry!
I think I finally have this working. I downloaded some demo Umbraco sites and found a Koiak Standard Site that did the sub-navigation similar to what I wanted. I took their two lines of IF statements and modified it to suite my needs. This is the code I ended up with:
Question though... is that the best way to do this? It appears to be working perfectly... but I'm not sure if there's a better way to be doing it. The two lines of code from the Koiak demo site that got this working for me were:
Hi Kris
Often when I need a small and simple submenu eg. in a sidebar or something like that, I tend to use this piece of code:
What the above code does is of course to render a submenu. In the top of the menu, there's a link to the "main-menu-page". Of course this can be removed easily. The code will continue to add additional levels of nodes if they are present in the content tree.
I don't know if this can inspire you, but now you've got the code for a quite easy submenu macro. Take it or leave it :)
/Kim A
is working on a reply...