Applying navigation order to Ultimate Navigation with XSLT
Hi,
I'm kinda new to Umbraco, and have implemented a navigation on a site I'm working on.
Firstly, I've created a doctype of mainNavItem as a true/false and I'm looking to adapt the ultimate navigation XSLT to only spit out items which have their mainNavItem box ticked, currently I'm having hassles with this.
Following on from this, I'm looking to create a doctype of perhaps navOrder, now the question is, could I set an ascending order on this navOrder id to generate the nav items in the order I desire?
Finally, I'm generating the pipes separators as <span class="pipe">|</span> straight after the <a>'s and I'd like to know the best way to tell XSLT to NOT generate the very last pipe.
To sum this up, the nav example directly below is how I want it, and the nav below that is how it stands currently
Ideal Nav - Home | Locations | Tools | Jobs | About | Contact
Current Nav - Home | Contact | About | Tools | Jobs | Locations |
For the sorting, I would suggest using Umbraco's built-in sort order. Right-click your parent node and click Sort, and put the nodes in the order you like.
If not, you could add a navOrder numeric field to your doctype if you wanted, and sort it in XSLT using:
Another, probably better, option might be to use a Multiple Content Picker to select/define your navigation items and order. This would allow you to choose the nodes to show in the navigation and sort them all in one view. Check out the Multi Node Tree Picker datatype from uComponents to achieve this. You could add the datatype to your Home node or in a "Backoffice"/Settings node if you have one.
With regard to the separators, you can test for the last position in your for-each loop in XSLT using the code below. Chriztian might get upset, but this is a simple way to get started :)
There are a few ways to go about this, just let us know what works for you and if you have any questions!
Also, FYI - typically the norm is to set the pages you DON'T want in your navigation, using a "Hide in navigation" checkbox, rather than specifying the ones to include. But if you have a lot of nodes at the same level that shouldn't be included, your way may be the way to go.
Applying navigation order to Ultimate Navigation with XSLT
Hi,
I'm kinda new to Umbraco, and have implemented a navigation on a site I'm working on.
Firstly, I've created a doctype of mainNavItem as a true/false and I'm looking to adapt the ultimate navigation XSLT to only spit out items which have their mainNavItem box ticked, currently I'm having hassles with this.
Following on from this, I'm looking to create a doctype of perhaps navOrder, now the question is, could I set an ascending order on this navOrder id to generate the nav items in the order I desire?
Finally, I'm generating the pipes separators as <span class="pipe">|</span> straight after the <a>'s and I'd like to know the best way to tell XSLT to NOT generate the very last pipe.
To sum this up, the nav example directly below is how I want it, and the nav below that is how it stands currently
Ideal Nav - Home | Locations | Tools | Jobs | About | Contact
Current Nav - Home | Contact | About | Tools | Jobs | Locations |
Hi Adam,
For the sorting, I would suggest using Umbraco's built-in sort order. Right-click your parent node and click Sort, and put the nodes in the order you like.
If not, you could add a navOrder numeric field to your doctype if you wanted, and sort it in XSLT using:
Another, probably better, option might be to use a Multiple Content Picker to select/define your navigation items and order. This would allow you to choose the nodes to show in the navigation and sort them all in one view. Check out the Multi Node Tree Picker datatype from uComponents to achieve this. You could add the datatype to your Home node or in a "Backoffice"/Settings node if you have one.
With regard to the separators, you can test for the last position in your for-each loop in XSLT using the code below. Chriztian might get upset, but this is a simple way to get started :)
There are a few ways to go about this, just let us know what works for you and if you have any questions!
Also, FYI - typically the norm is to set the pages you DON'T want in your navigation, using a "Hide in navigation" checkbox, rather than specifying the ones to include. But if you have a lot of nodes at the same level that shouldn't be included, your way may be the way to go.
-Tom
Hi Tom,
Thanks for your quick reply, this was very helpful!
Just after I posted, I figured out <xsl:if .... !=last()"> solution for the pipe thanks to W3 Schools and your advice as well.
I had no idea about the sort ability, so that's basically solved my main problem.
Your advice about hiding links from navigation were required makes sense, so I'll stick with the default.
Your link to Multi-Node Tree Picker has opened my eyes as to the components available for Umbraco, and this could be useful.
Thanks for your helpful advice Tom, and if/when I figure out how to give you karma, I'll send some your way.
Cheers
Adam
is working on a reply...