Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm pretty sure this is very basic but I can't seem to find a working example.
Here's our one level menu
<ul class="links"><li class="active"><a href="#" title="">home</a></li> <li><a href="#" title="">what we do</a></li> <li><a href="#" title="">who we work for</a></li> <li><a href="#" title="">who we are</a></li>
<li><a href="#" title="">contact us</a></li> </ul>
Send by mistake and no edit feature here, I'll start again:
Here's our one level menu driven by XSLT
<ul class="links"> <li class="active"><a href="#" title="">home</a></li> <li><a href="#" title="">what we do</a></li> <li><a href="#" title="">contact us</a></li></ul>
We need to set the class ‘active’ to whichever page we are on.
Any example or advice would be greatly appreciated.
Many thanks, Rich
You could try looking at http://our.umbraco.org/projects/cogworks---flexible-navigation
This package will probably do just what you're looking for, and it'll help you understand xslt more.
Cheers,
Chris
Thanks for the super fast reply chris!
I had a look your package already, it seems to deal with multi level navigation.
However ours is just a one level menu and surely a simple task everyone has to solve?
I was hoping for a much more straight forward solution.
Thanks, Rich
ah, ok. If it's only a single level then something like this should work
<xsl:param name="currentPage"/><xsl:variable name="level" select="1"/><xsl:template><xsl:variable name="nodeList" select="$currentPage/ancestor-or-self::node[@level=$level]/node"/><ul class="links"> <xsl:for-each select="$nodeList"> <li> <xsl:if test="$currentPage/ancestor-or-self::node /@id = current()/@id"> <xsl:text> current</xsl:text> </xsl:if> <a href="{umbraco.library:NiceUrl(current()/@id)}"> <xsl:value-of select="current()/@nodeName"/> </a> </li> </xsl:for-each></ul></xsl:template>
You may need to play with the 'level' param depending on your implementation.
hi Chris,
I use something like this for my topnav. I think this is what you are looking for:
<ul><xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/@id = current()/@id"> <xsl:attribute name="class">selected</xsl:attribute> </xsl:if> <xsl:if test="$currentPage/../@id = current()/@id"> <xsl:attribute name="class">selected</xsl:attribute> </xsl:if> <span><xsl:value-of select="@nodeName"/></span> </a> </li> </xsl:for-each></ul>
Neither of these examples work for me, none of the IF statements return a match.
Here's my code with the IF statements listed above:
<!-- Input the documenttype you want here --><xsl:variable name="level" select="1"/><xsl:template match="/"><!-- The fun starts here --><ul class="links"><xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']"> <li> <xsl:if test="$currentPage/@id = current()/@id"> <xsl:attribute name="class">active</xsl:attribute> </xsl:if> <xsl:if test="$currentPage/../@id = current()/@id"> <xsl:attribute name="class">active</xsl:attribute> </xsl:if> <xsl:if test="$currentPage/ancestor-or-self::node /@id = current()/@id"> <xsl:attribute name="class">active</xsl:attribute> </xsl:if> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/> </a> </li></xsl:for-each></ul>
Any more ideas?
hi Rich,
and if you set the level to 2 like this: <xsl:variable name="level" select="2"/>.
cheers Bart
Could you add your Content structure? Something like:
Content:
- menu item to display 1-- some page
- menu item to display 2
And where do you want to set the class the li tag or the a tag? This code sets the class to the link element.
<a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/> <xsl:if test="$currentPage/ancestor-or-self::node /@id = current()/@id"> <xsl:attribute name="class">active</xsl:attribute> </xsl:if></a>
Thanks, but it's still not working.
Maybe I'm confusing people, there is no content structure, it's just one level of navigation.
There is NO sub navigation.
------
Home Page - Home-Page.aspx
Who we work for - Who-We-Work-for.aspx
Contact Us page - Contact-Us.aspx
-------
This code is an example if I was on the Who-We-Work-For.aspx page.
<ul class="links"> <li><a href="/home.aspx">Home</a></li> <li class="current"><a href="/who-we-work-for.aspx">Who We Work For</a></li> <li><a href="/contact-us.aspx">Contact Us</a></li></ul>
This code is an example if I was on the Home.aspx page.
<ul class="links"> <li class="current"><a href="/home.aspx">Home</a></li> <li><a href="/who-we-work-for.aspx">Who We Work For</a></li> <li><a href="/contact-us.aspx">Contact Us</a></li></ul>
I was thinking this would be pretty standard and straight forward?
Ahhh! Simple indeed. I'd do something like this...
<xsl:template><ul class="links"> <xsl:for-each select="umbraco.library:GetXmlAll()/node[@level='1']> <li> <xsl:if test="$currentPage/@id = current()/@id"> <xsl:text> current</xsl:text> </xsl:if> <a href="{umbraco.library:NiceUrl(current()/@id)}"> <xsl:value-of select="current()/@nodeName"/> </a> </li> </xsl:for-each></ul></xsl:template>
cheers,doug.
Just a tip for all those with similar xslt issues: Have a look at the raw xml file in data/umbraco.config.
Once you have an understanding of this file's xml structure you will understand your xlst bugs easier.
Thanks Doug, that worked perfect! Cheers everyone else for their help too.
Here's the full code for anyone interested
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets "><xsl:output method="xml" omit-xml-declaration="yes" /><xsl:param name="currentPage"/><xsl:template match="/"><ul class="links"> <xsl:for-each select="umbraco.library:GetXmlAll()/node[@level='1']"> <li> <xsl:if test="$currentPage/@id = current()/@id"> <xsl:attribute name="class">active</xsl:attribute> </xsl:if> <a href="{umbraco.library:NiceUrl(current()/@id)}"> <xsl:value-of select="current()/@nodeName"/> </a> </li> </xsl:for-each></ul></xsl:template>
When you have a chance, please mark the solution.
Have done so now thanks Doug.
The only line I changed was
<xsl:if test="$currentPage/@id = current()/@id"> <xsl:text>current</xsl:text> </xsl:if>
to
<xsl:if test="$currentPage/@id = current()/@id"> <xsl:attribute name="class">active</xsl:attribute></xsl:if>
I couldn't get this to work with <xsl:for-eachselect="umbraco.library:GetXmlAll()/node[@level='1']">, but I did manage to make another solution work:
http://wifi.umbraco.org/forum/core/general/15423-Link-Class-Selected-Page?p=0#comment81313
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Setting current page class to "Selected"
I'm pretty sure this is very basic but I can't seem to find a working example.
Here's our one level menu
Send by mistake and no edit feature here, I'll start again:
I'm pretty sure this is very basic but I can't seem to find a working example.
Here's our one level menu driven by XSLT
We need to set the class ‘active’ to whichever page we are on.
Any example or advice would be greatly appreciated.
Many thanks, Rich
You could try looking at http://our.umbraco.org/projects/cogworks---flexible-navigation
This package will probably do just what you're looking for, and it'll help you understand xslt more.
Cheers,
Chris
Thanks for the super fast reply chris!
I had a look your package already, it seems to deal with multi level navigation.
However ours is just a one level menu and surely a simple task everyone has to solve?
I was hoping for a much more straight forward solution.
Thanks, Rich
ah, ok. If it's only a single level then something like this should work
You may need to play with the 'level' param depending on your implementation.
hi Chris,
I use something like this for my topnav. I think this is what you are looking for:
Neither of these examples work for me, none of the IF statements return a match.
Here's my code with the IF statements listed above:
Any more ideas?
Thanks, Rich
hi Rich,
and if you set the level to 2 like this: <xsl:variable name="level" select="2"/>.
cheers Bart
Could you add your Content structure? Something like:
Content:
- menu item to display 1
-- some page
- menu item to display 2
And where do you want to set the class the li tag or the a tag? This code sets the class to the link element.
Thanks, but it's still not working.
Maybe I'm confusing people, there is no content structure, it's just one level of navigation.
There is NO sub navigation.
------
Home Page - Home-Page.aspx
Who we work for - Who-We-Work-for.aspx
Contact Us page - Contact-Us.aspx
-------
This code is an example if I was on the Who-We-Work-For.aspx page.
This code is an example if I was on the Home.aspx page.
I was thinking this would be pretty standard and straight forward?
Ahhh! Simple indeed. I'd do something like this...
cheers,
doug.
Just a tip for all those with similar xslt issues: Have a look at the raw xml file in data/umbraco.config.
Once you have an understanding of this file's xml structure you will understand your xlst bugs easier.
Cheers,
Chris
Thanks Doug, that worked perfect! Cheers everyone else for their help too.
Here's the full code for anyone interested
When you have a chance, please mark the solution.
cheers,
doug.
Have done so now thanks Doug.
The only line I changed was
to
Many thanks, Rich
I couldn't get this to work with <xsl:for-eachselect="umbraco.library:GetXmlAll()/node[@level='1']">, but I did manage to make another solution work:
http://wifi.umbraco.org/forum/core/general/15423-Link-Class-Selected-Page?p=0#comment81313
is working on a reply...