Hi Graeme and welcome to our and the joyfull world of Umbraco development :)
I think your sample looks very identical to what you get from the "navigation prototype", which is a predefined XSLT snippet that you can use as a starting point for your navigation.
Therefore I think you actually just need to go to the developer section, right click "XSLT" and create a new XSLT macro and choose the "navigation prototype" from the dropdown that appears.
There you will notice that there this section beneath the opening <li> element
<xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id"> <!-- we're under the item - you can do your own styling here --> <xsl:attribute name="class">selected</xsl:attribute> </xsl:if>
This is where the magic of adding the active class happens.
Hope this helps, otherwise don't hesitate to ask :)
Glad you got it working - I must admit I'm a bit embarresed. Sam is totally right...I'll remember to wear my glasses next time I answer a post with code samples, sorry Sam ;-)
Ive just been testing my nav again, the nav is great for the level 3 nav, but when i click on the level 2 it shows the parent which is home.Im trying to write a if statement to say, if on level 2 then show current nodeName? is this possible?
That should be possible but perhaps it's better to make use of the @path attribute?
it conatins the @path id's listing them as "-1,1100,1304,1540" for instance. The position of the parent id is always the same in this sequence, so by using umbraco.library:Split() on this value you should be able to get the value of the parent id, which is always the same in the same spot no matter how far down you are in the structure.
So maybe it would be easier to make a comparison on this?
Xslt - Newbie help with active class and listing level nodes
I was wondering if anyone could help me, Im pretty new to umbraco and Xslt.
ive been trying to unsuccessfully create a left hand nav for our website. However I cannot seem to get all of it working.
I am trying to get the nav to show the selected level 2 node page and then the selected level 3 node aswell when active.
-Homepage
--House
---windows
---doors
Below is an html version of what im trying to achieve
Below is my xslt which only shows the level 3 nodes.
Hi Graeme and welcome to our and the joyfull world of Umbraco development :)
I think your sample looks very identical to what you get from the "navigation prototype", which is a predefined XSLT snippet that you can use as a starting point for your navigation.
Therefore I think you actually just need to go to the developer section, right click "XSLT" and create a new XSLT macro and choose the "navigation prototype" from the dropdown that appears.
There you will notice that there this section beneath the opening <li> element
<xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
<!-- we're under the item - you can do your own styling here -->
<xsl:attribute name="class">selected</xsl:attribute>
</xsl:if>
This is where the magic of adding the active class happens.
Hope this helps, otherwise don't hesitate to ask :)
/Jan
Thanks for the quick reply Jan, I have got the selected to work on the level 3 nodes :)
I just need to get the level 2 bit working so that it shows the parent node and adds the selected class ( where i have the link with house)?
thanks again for the getting back to me so quickly :)
ive been playing arround with it a bit more and still cannot get the parent node to appear, and i get errors with the following?
Is there any recommended reading material or sources for xslt? I have to learn it pretty quickly.
Thanks
Hi Graeme
Not sure what it is you've got going on in the above...what kind of errors do you receive?
/Jan
Jan, im trying to show 2 levels, my level 2 parent node, and the level 3 nodes that are allocated to it.
To call the level 3 nodes the below works fine
But then before the "for each" im trying to display a link to the parent node, is this where im going wrong?
Jan the error im receiving is
Thanks
Hi Graeme
Does it work if you check "skip error testing" when you save the XSLT?
Sometimes the passed id's is not known on the runtime of the XSLT, which is why you get an error probably.
/Jan
Hi Graeme,
Isn't this the old xml schema?
Maybe you're mixing new with old?
Could try this:
Sam.
Hi Sam
If it was the old schema some of the previous code would not have been working, which it apparently has :-)
The above error is something that many people gets confused about - and with good reason.
Cheers
/Jan
Thanks Sam and Jan I got it working, I must have been mixing old and new schemas.
Thanks again :)
Hi Graeme
Glad you got it working - I must admit I'm a bit embarresed. Sam is totally right...I'll remember to wear my glasses next time I answer a post with code samples, sorry Sam ;-)
/Jan
lol. I'm just pleased that my learning has finally paid off a bit with being able to help out :)
Sam.
-Homepage
--House
---windows
---doors
Ive just been testing my nav again, the nav is great for the level 3 nav, but when i click on the level 2 it shows the parent which is home.Im trying to write a if statement to say, if on level 2 then show current nodeName? is this possible?
Hi Graeme..
That should be possible but perhaps it's better to make use of the @path attribute?
it conatins the @path id's listing them as "-1,1100,1304,1540" for instance. The position of the parent id is always the same in this sequence, so by using umbraco.library:Split() on this value you should be able to get the value of the parent id, which is always the same in the same spot no matter how far down you are in the structure.
So maybe it would be easier to make a comparison on this?
Does it make sense?
/Jan
yes it does Jan, do you have any examples of @path in use?
Jan ive got it working, it may not be the best way of doing it but its working :) Thanks again!! :)
is working on a reply...