Copied to clipboard

Flag this post as spam?

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


  • Adam 7 posts 27 karma points
    Nov 23, 2010 @ 03:56
    Adam
    0

    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">&#124;</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 |

    Any help would be greatly appreciated!
    Cheers
    Adam

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 23, 2010 @ 05:00
    Tom Fulton
    0

    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:

    <xsl:for-each select="..your code..">
        <xsl:sort select="navOrder" data-type="number" order="ascending" />
    .....


    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 :)

    <xsl:if test="position() != last()">
        <span class="pipe">&#124;</span>
    </xsl:if>


    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

  • Adam 7 posts 27 karma points
    Nov 23, 2010 @ 06:09
    Adam
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft