Here's how I'd approach it - the structure in Content should look something like this:
Structure:
==========
Content
Site 1 # "Home"
Projects
Project 1
Project 2
...
About Us
People
Contact
Jobs
Map
...
Site 2
...
Output:
=======
ProjectsAbout UsContact
Project 1 People Jobs
Project 2 Map
- so you can use a macro like this one:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
exclude-result-prefixes="umb"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<xsl:template match="/">
<!-- Process all of the heading nodes (1st level below root) -->
<xsl:apply-templates select="$siteRoot/*[@isDoc][showInFooter = 1]" mode="header" />
</xsl:template>
<!-- Template for the headers -->
<xsl:template match="*[@isDoc]" mode="header">
<!-- Select the sub pages (if any) -->
<xsl:variable name="subPages" select="*[@isDoc][showInFooter = 1]" />
<!-- Only output if any sub pages to link to -->
<xsl:if test="$subPages">
<h1>
<xsl:value-of select="@nodeName" />
</h1>
<ul>
<!-- Use the link mode template for the links -->
<xsl:apply-templates select="$subPages" mode="link" />
</ul>
</xsl:if>
</xsl:template>
<!-- Template for the links -->
<xsl:template match="*[@isDoc]" mode="link">
<li>
<a href="{umb:NiceUrl(@id)}">
<xsl:value-of select="@nodeName" />
</a>
</li>
</xsl:template>
</xsl:stylesheet>
If your structure doesn't look like this, you should only need to adjust the siteRoot variable - let us know, and we'll help you out.
- this will look not only for children, but for their children as well and further down, so we put a maximum level of 4 in there to minimize the number of nodes searched. Just change the 4 to the actual level you need...
Footer Navigation Multiple Levels
Hi guys,
I'm trying to make a footer navigation area with multiple level links. I already have a property called "showInFooter" with a for each loop.
I want the first level (the top level) to be displayed as a heading and level 2 (the sub pages) to be displayed as links underneath.
How would I accomplish this using my current macro?
Hi Devin,
Here's how I'd approach it - the structure in Content should look something like this:
Structure: ========== Content Site 1 # "Home" Projects Project 1 Project 2 ... About Us People Contact Jobs Map ... Site 2 ... Output: ======= Projects About Us Contact Project 1 People Jobs Project 2 Map- so you can use a macro like this one:
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:umb="urn:umbraco.library" exclude-result-prefixes="umb" > <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" /> <xsl:param name="currentPage" /> <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" /> <xsl:template match="/"> <!-- Process all of the heading nodes (1st level below root) --> <xsl:apply-templates select="$siteRoot/*[@isDoc][showInFooter = 1]" mode="header" /> </xsl:template> <!-- Template for the headers --> <xsl:template match="*[@isDoc]" mode="header"> <!-- Select the sub pages (if any) --> <xsl:variable name="subPages" select="*[@isDoc][showInFooter = 1]" /> <!-- Only output if any sub pages to link to --> <xsl:if test="$subPages"> <h1> <xsl:value-of select="@nodeName" /> </h1> <ul> <!-- Use the link mode template for the links --> <xsl:apply-templates select="$subPages" mode="link" /> </ul> </xsl:if> </xsl:template> <!-- Template for the links --> <xsl:template match="*[@isDoc]" mode="link"> <li> <a href="{umb:NiceUrl(@id)}"> <xsl:value-of select="@nodeName" /> </a> </li> </xsl:template> </xsl:stylesheet>If your structure doesn't look like this, you should only need to adjust the siteRoot variable - let us know, and we'll help you out.
/Chriztian
Thank you Chriztian that was exactly what I was looking for!
If I wanted to add another level, would I just change:
to this?
Hi Devin,
It depends on what you want - if you set level to 2 on the siteRoot variable, you decrease the number of nodes output (try it).
If you want to include links for nodes at a level deeper, you would just add those to the $subPages variable, e.g.:
- this will look not only for children, but for their children as well and further down, so we put a maximum level of 4 in there to minimize the number of nodes searched. Just change the 4 to the actual level you need...
Was that what you were trying to do?
/Chriztian
Thank you kindly for your help. That makes perfect sense and was exactly what I wanted to do. :
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.