<!-- Input the documenttype you want here --> <xsl:variable name="level" select="3"/>
<xsl:template match="/">
<!-- The fun starts here --> <ul> <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '3']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/> </a> </li> </xsl:for-each> </ul>
</xsl:template>
</xsl:stylesheet>
This is the "List Subpages by Level" XSLT template already built into Umbraco. But I also need to show the section parent page so the users can see which section they are in.
So if the menu hiararchy is:
Home
- 1. Numbers
-- 1.1. One
-- 1.2. Two
- 2. Colours
-- 2.1. Blue
-- 2.2. Red
then on the Blue and Red pages I also need a link to Colours in the sub navigation. I hope this makes sense.
I'm using Umbraco 4.9.0 if that helps in any way. Any help is gratefully accepted.
Well spotted Dennis - that must've been an auto-completion error on my part - I've corrected my code so future copy/paste actions doesn't fail.
@Trine: The first error is of course that you needed to close the <xsl:stylesheet> element - the second error, I think, is some sort of typo or a weird character - can you check that you really have </xsl:stylesheet> and not some variation (e.g. 'styleSheet' or 'styllesheet' etc.) ?
@Chriztian: The </xsl:stylesheet> vanishes down past the bottom of the input window and it won't let me scroll down past </xsl:template> to see it, but it is there. I'll put it down to an Umbraco quirk. :-) I think I tried to put too many </xsl:stylesheet> in to close it and of course that caused an error.
@Dennis: Your amended version of the code worked better (no error messages when I try to save), but on the site itself I get: "Error parsing XSLT file: \xslt\BranchSubNav4.xslt" where the code should work? What's happening?
@Trine: Ah yes, but of course - a duplicate <xsl:stylesheet> element would generate that error too.
@Nadine: Did you try the fixed version? I've fixed the error related to the $currentSection parameter since posting the original. Could you try adding this querystring to the URL of the page you're running the macro on: ?umbDebugShowTrace=True ? This should output a more detailed error message...
Note: This macro will not work if you run it on the "Home" page; it only works on the subpages.
I found a simplistic solution that might help you @Trine that you can build on, it still has a for-each statement and using @Chriztian's methodology should be in an apply templates statement but I don't want to mess with it any more because it works. Hope it's useful for you...
Hi @Chriztian yes I tried the fix you suggested but it didn't work for me I did put in the trace URL and it didn't show any extra information on the page or is the trace info written to a log file somewhere?
I've had a go at getting rid of that for-each statement as it didn't recurse more than the 2 levels and I have surprised myself and done it successfully, I just had to stick in some if statements to control the formatting via CSS. It doesn't look as sexy as your code @Chriztian but it works for me. Love your work!
@nadine: Awesome! That worked! I just needed to change the level values and it worked perfectly! And I can see how it relates to @Chriztian's code as well so I have definitely learned something here!
One quick question though: how do I style the <li> and <a> of the current page so the user can see which page they are on? Doing it on a non-responsive navigation is easy, but I'm unsure on Umbraco responsive ones. Where in this code do I specify the class, or is that completely the wrong way of doing it?
I know I posted this as solved, but since then the client has added another level to the page structure and now the solution doesn't work!
@nadine: Having some trouble with the second code you offered up. The first one worked perfectly, but the client has since decided to add another level in and that meant that on the pages I need it it's only showing the parent page.
The second code only seems to show either the current page, not the parent page, current page and sibling page.
So you can see the levels I'm dealing with, this is the full breadcrumb for the pages I need this code to work on: Home - Branches - County - Branch - Team. The code needs to work on the last level and I can't get it to work!
Is there any way of getting the first code to work on a level this deep?
Showing parent page in sub navigation
My website has several sections, each with subpages. On these subpages I can use this XSLT to show all the subpages for the current section:
<?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" xmlns:twitter.library="urn:twitter.library" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch" xmlns:google.maps="urn:google.maps"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets twitter.library PS.XSLTsearch google.maps ">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="3"/>
<xsl:template match="/">
<!-- The fun starts here -->
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '3']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
This is the "List Subpages by Level" XSLT template already built into Umbraco. But I also need to show the section parent page so the users can see which section they are in.
So if the menu hiararchy is:
Home
- 1. Numbers
-- 1.1. One
-- 1.2. Two
- 2. Colours
-- 2.1. Blue
-- 2.2. Red
then on the Blue and Red pages I also need a link to Colours in the sub navigation. I hope this makes sense.
I'm using Umbraco 4.9.0 if that helps in any way. Any help is gratefully accepted.
:-)
Hi Trine,
Here's a chunk that usually does it for me when I need this:
/Chriztian
(Edit: Fixed an error in a select attribute)
Hi Chriztian!
Thanks for that! It looks like it should work, but the client's server is down so I can't test it at the moment. :-(
I'll try again tomorrow and let you know!
Trine
Hi Chriztian!
I'm getting an error when I try the code:
My code is:
<?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" xmlns:twitter.library="urn:twitter.library" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch" xmlns:google.maps="urn:google.maps"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets twitter.library PS.XSLTsearch google.maps ">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<!-- The level of your "Home" node - usually 1 -->
<xsl:variable name="homeLevel" select="1" />
<xsl:variable name="sectionsLevel" select="$homeLevel + 1" />
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = $homeLevel]" />
<xsl:variable name="currentSection" select="$currentSection/ancestor-or-self::*[@level = $sectionsLevel]" />
<xsl:template match="/">
<ul>
<!-- Start at the current section -->
<xsl:apply-templates select="$currentSection" />
</ul>
</xsl:template>
<!-- Template for any page -->
<xsl:template match="*[@isDoc][not(umbracoNaviHIde = 1)]">
<xsl:variable name="subPages" select="*[@isDoc][not(umbracoNaviHide = 1)]" />
<li>
<!-- Add class=selected if this is the current page -->
<xsl:if test="@id = $currentPage/@id"><xsl:attribute name="class">selected</xsl:attribute></xsl:if>
<a href="{umbraco.library:NiceUrl(@isDoc)}">
<xsl:value-of select="@nodeName" />
</a>
<!-- Process subPages (if any) -->
<xsl:if test="$subPages">
<ul>
<xsl:apply-templates select="$subPages" />
</ul>
</xsl:if>
</li>
</xsl:template>
I've tried adding </xsl:stylesheet> to the end after </xsl:template>, but that is giving me this error:
Any ideas?
Trine
Hi Trine,
I think I spotted what gives you the error: Try this one and see if it´s goes better.
The differnce between the code I posted and this one you have tried is, the select in the variable called currentSection. I have change
To
Hope this helps you.
/Dennis
Well spotted Dennis - that must've been an auto-completion error on my part - I've corrected my code so future copy/paste actions doesn't fail.
@Trine: The first error is of course that you needed to close the
<xsl:stylesheet>
element - the second error, I think, is some sort of typo or a weird character - can you check that you really have</xsl:stylesheet>
and not some variation (e.g. 'styleSheet' or 'styllesheet' etc.) ?/Chriztian
@Chriztian: The </xsl:stylesheet> vanishes down past the bottom of the input window and it won't let me scroll down past </xsl:template> to see it, but it is there. I'll put it down to an Umbraco quirk. :-) I think I tried to put too many </xsl:stylesheet> in to close it and of course that caused an error.
@Dennis: Your amended version of the code worked better (no error messages when I try to save), but on the site itself I get: "Error parsing XSLT file: \xslt\BranchSubNav4.xslt" where the code should work? What's happening?
Thank you both for your help so far!
Trine
I've tried this code too and it doesn't work for me! It can't find that first 'currentSection' path so it won't find the subsequent sub pages.
@Trine: Ah yes, but of course - a duplicate
<xsl:stylesheet>
element would generate that error too.@Nadine: Did you try the fixed version? I've fixed the error related to the $currentSection parameter since posting the original. Could you try adding this querystring to the URL of the page you're running the macro on:
?umbDebugShowTrace=True
? This should output a more detailed error message...Note: This macro will not work if you run it on the "Home" page; it only works on the subpages.
/Chriztian
I found a simplistic solution that might help you @Trine that you can build on, it still has a for-each statement and using @Chriztian's methodology should be in an apply templates statement but I don't want to mess with it any more because it works. Hope it's useful for you...
Hi @Chriztian yes I tried the fix you suggested but it didn't work for me I did put in the trace URL and it didn't show any extra information on the page or is the trace info written to a log file somewhere?
I've had a go at getting rid of that for-each statement as it didn't recurse more than the 2 levels and I have surprised myself and done it successfully, I just had to stick in some if statements to control the formatting via CSS. It doesn't look as sexy as your code @Chriztian but it works for me. Love your work!
Hope you have found this helpful @Trine.
@nadine: Awesome! That worked! I just needed to change the level values and it worked perfectly! And I can see how it relates to @Chriztian's code as well so I have definitely learned something here!
One quick question though: how do I style the <li> and <a> of the current page so the user can see which page they are on? Doing it on a non-responsive navigation is easy, but I'm unsure on Umbraco responsive ones. Where in this code do I specify the class, or is that completely the wrong way of doing it?
Strike that last one, I've found the solution! Add
<xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
<xsl:attribute name="class">current-page</xsl:attribute>
</xsl:if>
under the <li> and <a> I want to have the class name "current-page".
Got this from http://our.umbraco.org/forum/developers/xslt/24351-Navigation-Current-state-on-parent-node so I'm not taking credit for it.
@nadine, @Chriztian and @Dennis: Thank you all so much for your help!! Kudos to all!
Trine :-)
I know I posted this as solved, but since then the client has added another level to the page structure and now the solution doesn't work!
@nadine: Having some trouble with the second code you offered up. The first one worked perfectly, but the client has since decided to add another level in and that meant that on the pages I need it it's only showing the parent page.
The second code only seems to show either the current page, not the parent page, current page and sibling page.
So you can see the levels I'm dealing with, this is the full breadcrumb for the pages I need this code to work on: Home - Branches - County - Branch - Team. The code needs to work on the last level and I can't get it to work!
Is there any way of getting the first code to work on a level this deep?
is working on a reply...