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.
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<=$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.
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.
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<=$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
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.
I hard coded it. The simplest solution is often the best. Thanks
is working on a reply...