Copied to clipboard

Flag this post as spam?

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


  • Ronnie Overby 14 posts 37 karma points
    Jan 20, 2011 @ 02:13
    Ronnie Overby
    0

    Problem creating navigation item for level 1 home page

    Using 4.6.1. 

    I am new to xslt and umbraco. I'm building xslt for main navigation for my site, but I'm struggling trying to include my home page document, which is the only thing on level 1, along side my level 2 documents. 

    Here is what I have so far: http://pastebin.com/xqBCYWiD

    Look for the comment: <!-- I think I need to put the Home Page list item here!!! BUT HOW! -->

    Thanks for any help.

  • Sascha Wolter 615 posts 1101 karma points
    Jan 20, 2011 @ 03:27
    Sascha Wolter
    0

    Hi Ronnie,

    in your xsl:for-each loop you have the following select statement:

    $currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']

    with $level being set to 1. What this does is basically: go from the current page to either itself or any ancestor node that has the attribute isDoc and a level attribute of 1, then loop through all direct children of that which have an attribute isDoc etc. That means if you have a content structure like

    Home

      - first page

      - second page

      - third page

    the xpath will land at 'Home' and then loop through all 3 child pages, however will ignore the 'Home' node as it is not part of the xpath expression. Two solutions here:

    either get the 'Home' node into the query as well: 

    $currentPage/ancestor-or-self::* [@isDoc and @level&lt;=$level and string(umbracoNaviHide) != '1']  (with $level set to 2)

    or treat it extra (my preference actually) by just adding a hard coded link to the homepage before the for-each loop.

    Hope that helps,

    Sascha

  • Paul Blair 466 posts 731 karma points
    Jan 20, 2011 @ 03:37
    Paul Blair
    0

    I think you could also do:

    $currentPage/ancestor-or-self::* [@isDoc and @level=$level]/descendant-or-self::node [@isDoc and string(umbracoNaviHide) != '1']

    But both these options wil have issues if you sort using the @sortOrder param as Home will have a sortorder of 1 as will the first node below home.

    As Sascha also suggests adding a hard coded link is a good option i.e.

    <li><a href="/">home</a</li>
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
    ...
  • Ronnie Overby 14 posts 37 karma points
    Jan 20, 2011 @ 03:39
    Ronnie Overby
    0

    I hard coded it. The simplest solution is often the best. Thanks

Please Sign in or register to post replies

Write your reply to:

Draft