Hello there, I am running the latest Umbraco 4.0.2.1 on windows xp, .NET 3.5.
I have a menu, where by there are top level menu items and some of these pages can have children, and i only want to show these children if the parent page is selected, but i cant get the if condition to work properly here is my xslt:
At the moment it does get out the children for the page that has children but when clicking on any other page it renders the rest of the top level pages as sub level ones, i am very new to umbraco and xslt!
<a href="{umbraco.library:NiceUrl($rootNode/@id)}"> <!-- Add the class selected if the root node ID matches our current node ID in the for each loop --> <xsl:if test="$rootNode/@id = $currentPage/@id"> <xsl:attribute name="class"> <xsl:text> on </xsl:text> </xsl:attribute> </xsl:if> <xsl:value-of select="$rootNode/@nodeName" /> </a>
</li>
<xsl:for-each select="$currentPage/ancestor-or-self::node/node [@level = 2 and string(data[@alias='umbracoNaviHide']) != '1']"> <li>
<xsl:if test="@nodeName = 'Contact'"> <xsl:attribute name="class"> <xsl:text> contact </xsl:text> </xsl:attribute> </xsl:if> <a href="{umbraco.library:NiceUrl(@id)}"> <!-- Add the class selected if the currentpage or parent nodes (up the tree to the root) ID matches our current node ID in the for each loop --> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <xsl:attribute name="class"> <xsl:text> on </xsl:text> </xsl:attribute> </xsl:if> <xsl:value-of select="@nodeName" />
<!-- Input the documenttype you want here --> <!-- Typically '1' for topnavigtaion and '2' for 2nd level --> <!-- Use div elements around this macro combined with css --> <!-- for styling the navigation --> <xsl:variable name="level" select="1"/>
<xsl:template match="/">
<!-- The fun starts here --> <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/ancestor-or-self::node/@id = current()/@id"> <!-- we're under the item - you can do your own styling here --> <xsl:attribute name="class">current</xsl:attribute> </xsl:if> <xsl:value-of select="@nodeName"/> </a> <xsl:if test="($currentPage/@id=current()/@id and count(current()/node) > 0) or ($currentPage/@parentID = ./@id)"> <ul> <xsl:for-each select="current()/node"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <!-- we're under the item - you can do your own styling here --> <xsl:attribute name="class">current</xsl:attribute> </xsl:if> <xsl:value-of select="@nodeName"/> </a> </li> </xsl:for-each> </ul> </xsl:if> </li> </xsl:for-each> </ul>
Thank you for your help, I have installed the package from your first post and it works exactly how i want it to apart from it doesnt show my home page node at the top, any idea why?
Thank you once again for helping me out, i put the code in and it did get out the home link, all be it in a seperate ul li list, i tried just pasting in the section that does the li but it wouldnt parse the file, also when i put all of it in, and then clicked on another page it put home as a child of that page.
Hi guys, i have tried putting in both your code snippets but i cant get them to work, just get a error reading xslt file here is my code that is from the package above which works that doesnt have the home link in, if anyone could change the code and show me where it should go?
<!--This sets the level that the nav starts at and tells us if we should recurse through child elements--> <xsl:variable name="startDepth" select="/macro/startingLevel" /> <xsl:variable name="recurse" select="/macro/recurse" /> <xsl:variable name="selectBranches" select="/macro/selectBranches"></xsl:variable> <xsl:variable name="maxMenuDepth" select="/macro/maxMenuDepth"></xsl:variable> <!--Alternate page title variable in here-->
<!--Styles for the navigation--> <xsl:variable name="ulBaseClass" select="/macro/ulBaseClass"></xsl:variable> <xsl:variable name="branchClass" select="/macro/branchClass"></xsl:variable> <xsl:variable name="selectedClass" select="/macro/selectedClass"></xsl:variable>
<!--This calls first iteration of the navigation, sending the first node at the correct depth found in the ancestors of the current page--> <xsl:template match="/"> <xsl:call-template name="nodeIterator"> <xsl:with-param name="parentNode" select="$currentPage/ancestor-or-self::node[@level=$startDepth] [string(data [@alias='umbracoNaviHide']) != '1']" /> <xsl:with-param name="pseudoCurrentPage" select="$currentPage" /> </xsl:call-template> </xsl:template>
<xsl:template name="nodeIterator"> <xsl:param name="parentNode" /> <xsl:param name="pseudoCurrentPage" /> <!-- do not show info doc node types-->
<!--for each node in the parent node that is not hidden by Umbraco--> <xsl:for-each select="$parentNode/node [string(data [@alias='umbracoNaviHide']) != '1']">
<!--Set the current node id i.e. the node we have looped to not the current page--> <xsl:variable name="currentNodeID" select="./@id" />
<!--Is the node a branch? i.e. are there children to and it is in the colletion of ancestor nodes --> <xsl:variable name="isBranch"> <xsl:choose> <xsl:when test="$pseudoCurrentPage/ancestor-or-self::node[@id = $currentNodeID]/child::node">1</xsl:when> </xsl:choose> </xsl:variable>
<!--Is the node selected? i.e. is it the same as the currentPage node--> <xsl:variable name="isSelected"> <xsl:choose> <xsl:when test="$pseudoCurrentPage/@id = $currentNodeID">1</xsl:when> </xsl:choose> </xsl:variable>
Am i right in thinking that in the code it calls other parts of it to perform the loops etc? is that why when i change or paste code in places it errors?
Right ok, I have done that already, every other page in the menu when selected turns on but putting the css class of on onto the <a> but when i am on the home link it doesnt put any class on.....?
1. Add the umbracoRedirect property alias to your
document type with a content picker and you can then allow choose a
node ID that you want the page to redirect to (from the wiki)
2. Using inline ASP.NET scripting in the header part of the (master) page: <% Response.Redirect("/mypage.aspx"); %>
Hello, what i am trying to do is use the xlst script that Masood Afzal has kindly altered for me, to turn on (in css) the parent page from the child that you are on so like:
Home About Us - css class = on Sub page of about us - css class also on
So as that when you are on a sub page you know what section you are in, does that make sense?
XSLT Menu Problem - Newbie!
Hello there, I am running the latest Umbraco 4.0.2.1 on windows xp, .NET 3.5.
I have a menu, where by there are top level menu items and some of these pages can have children, and i only want to show these children if the parent page is selected, but i cant get the if condition to work properly here is my xslt:
At the moment it does get out the children for the page that has children but when clicking on any other page it renders the rest of the top level pages as sub level ones, i am very new to umbraco and xslt!
Please help!
Have a look at this package which can be used for same purpose.
Cogworks - Flexible Navigation
Link: http://our.umbraco.org/projects/cogworks---flexible-navigation
Another sample is here:
Thank you for your help, I have installed the package from your first post and it works exactly how i want it to apart from it doesnt show my home page node at the top, any idea why?
My content site map in umbraco is like this:
Home
About us
child page
Contact us
Web
Etc
And the menu just pulls in from about us down when the startingLevel = 1
Any ideas?
Following xslt should display homepage link.
Thank you once again for helping me out, i put the code in and it did get out the home link, all be it in a seperate ul li list, i tried just pasting in the section that does the li but it wouldnt parse the file, also when i put all of it in, and then clicked on another page it put home as a child of that page.
Any ideas?
Thanks again in advance
You're always going to want a home link, so why not just hard-code it?
What about changing your xslt template to something like below (as mentioned by dandrayne):
Hi guys, i have tried putting in both your code snippets but i cant get them to work, just get a error reading xslt file here is my code that is from the package above which works that doesnt have the home link in, if anyone could change the code and show me where it should go?
I want it as the top <li> in the list.
thanks once again!
Here you go. Its works fine at my end.
That xslt creates the following output for me:
<ul class=" lv0">
<li><a class="homelink" href="/home.aspx">Home</a>
<ul class=" lv1">
<li class="on "><a href="/about-us.aspx" class="on ">About Us</a>
<ul class="lv2">
<li class=""><a href="/about-us/ben.aspx" class="">Ben</a></li>
</ul>
</li>
<li class=""><a href="/web.aspx" class="">Web</a></li>
<li class=""><a href="/print.aspx" class="">Print</a></li>
<li class=""><a href="/portfolio.aspx" class="">Portfolio</a></li>
<li class=""><a href="/contact.aspx" class="">Contact</a></li>
<li class=""><a href="/news.aspx" class="">News</a></li>
</ul>
</li>
</ul>
Which isnt quite right?!
You can rearrange/change it in xslt template.
But every time i change it or move things around i get an error, apologies for this but until the other day ive never used xslt
This is another simple version. Its not based on above navigation package. It requires no parameters etc.
I cant seem to get anything to work now =(
i would like to use the cog menu but just add in the homepage link in an <li> with no extra <ul>
I dont know what im doing wrong?
Am i right in thinking that in the code it calls other parts of it to perform the loops etc? is that why when i change or paste code in places it errors?
This is cogs navigation altered for you:
It will display homepage link as first <li> item
This is FANTASTIC thank you very much!!!!!
I am now trying to code in the condition if the page is selected so far i have this and doesnt work....
You do not need to change this code for selcted nodes. its the work. Just pass selected css class name as macro parameter e.g. "on"
Right ok, I have done that already, every other page in the menu when selected turns on but putting the css class of on onto the <a> but when i am on the home link it doesnt put any class on.....?
Following code well do the job.
You sir are a genius! Thank you!
I also thank you for your patience with me!
I have one final question...
Is there a way when you are on a child page to turn the parent on ?
Thank you again :)
If anyone could help with this last thing i would be very grateful
Please!!!?
Hi ben, two ways of doing this is to:
1. Add the umbracoRedirect property alias to your document type with a content picker and you can then allow choose a node ID that you want the page to redirect to (from the wiki)
2. Using inline ASP.NET scripting in the header part of the (master) page:
<% Response.Redirect("/mypage.aspx"); %>
>Tommy
... assuming you mean redirecting by "turning on", that is
Hello, what i am trying to do is use the xlst script that Masood Afzal has kindly altered for me, to turn on (in css) the parent page from the child that you are on so like:
Home
About Us - css class = on
Sub page of about us - css class also on
So as that when you are on a sub page you know what section you are in, does that make sense?
Hi Ben,
Set the css class for 'branchClass' parameter of macro and this will do the trick.
selectedClass is current node.
branchClass is parent node of selected node.
You can set both to your css class e.g. "on"
Thank you
Thank you
Thank you
Thank you
Thank you
=)
Please remember to mark correct answers as "Mark as helpful reply" (Thumb up icon on right side) so other users can jump to correct answer.
Says i cant vote for them as dont have enough karma points!
is working on a reply...