I've read somewhere that the xslt reads from level 1 instead of level 0. Are there ways around this, so I can get the root of the page also as a item in the menu?
Could you also give me hint with the following part? This can be done better I think.
You can leave out the first <xsl:for-each>, as it will never be hit - there is no "@level='0'" in the XML cache (in \data\umbraco.config), the first level of <node> is "@level=1" (usually the root of your website).
Then for the "class" attribute of the link, if it's the current page, then you'd be adding 2 "class" attributes; i.e. it would look like this:
I'm curious about the "$currentPage/ancestor-or-self::node/@id" part too ... try removing the "ancestor-or-self::node" bit ... but I'm not 100% of your content structure, so it might need it? Play around with it, see what works best!
The "node" template is your general output (@Lee: Don't worry about duplicate class attributes - XSLT will only generate one, so the second will overwrite the first, if necessary).
The last (empty) template takes care of nodes with the umbracoNaviHide flag checked
The "apply-templates" instruction collects the $siteRoot node along with its childnodes, and tell the processor to go do its thing with 'em.
I'll explain the possibilities for setting the "current" class a little bit more in detail:
If (as I was guessing from the above) the current page will only ever be one of the pages output for navigation (i.e., no level 3 nodes exist) you can do like the above, and check if the @id of the node currently being output is equal to the @id of $currentPage:
<xsl:if test="@id = $currentPage/@id"> ...
If you have subpages (level 3 or more) and you want to keep the current class on the parent nodes of it, check for the presence of currentPage in the descendant-or-self:: axis:
xslt can be done more simpe, but how?
Hi,
I like something to do as the following, but can be done simper and more effective. (its about the level parameter) Any ideas?
Sorry, not clear like this. The second [@level='0']/node has to be [@level='1']/node
Hi Roel,
I think you have 2 options here. First, try a
xsl:for-each select="$currentPage/ancestor-or-self::node [@level='0' or @level='1']/node [string(data [@alias='umbracoNaviHide']) != '1']
You'd only need 1 for each then and you could sort by level perhaphs.
Secondly, you could try to use a template and call that twice with a different parameter?
Does this help a bit?
Peter
Hi Peter,
Thanks for your quick reply!
I've read somewhere that the xslt reads from level 1 instead of level 0. Are there ways around this, so I can get the root of the page also as a item in the menu?
Could you also give me hint with the following part? This can be done better I think.
<xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
Hi Roel,
You can leave out the first <xsl:for-each>, as it will never be hit - there is no "@level='0'" in the XML cache (in \data\umbraco.config), the first level of <node> is "@level=1" (usually the root of your website).
Then for the "class" attribute of the link, if it's the current page, then you'd be adding 2 "class" attributes; i.e. it would look like this:
I'd suggest replacing it with an <xsl:choose> condition. Here's a re-worked snippet:
I'm curious about the "$currentPage/ancestor-or-self::node/@id" part too ... try removing the "ancestor-or-self::node" bit ... but I'm not 100% of your content structure, so it might need it? Play around with it, see what works best!
Cheers, Lee
Hi Roel,
I'd do something like this:
The "node" template is your general output (@Lee: Don't worry about duplicate class attributes - XSLT will only generate one, so the second will overwrite the first, if necessary).
The last (empty) template takes care of nodes with the umbracoNaviHide flag checked
The "apply-templates" instruction collects the $siteRoot node along with its childnodes, and tell the processor to go do its thing with 'em.
/Chriztian
I'll explain the possibilities for setting the "current" class a little bit more in detail:
If (as I was guessing from the above) the current page will only ever be one of the pages output for navigation (i.e., no level 3 nodes exist) you can do like the above, and check if the @id of the node currently being output is equal to the @id of $currentPage:
If you have subpages (level 3 or more) and you want to keep the current class on the parent nodes of it, check for the presence of currentPage in the descendant-or-self:: axis:
Hope it clears up a couple of things,
/Chriztian
Thanks guys! This solves my question!
Roel
is working on a reply...