Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Devin 87 posts 251 karma points
    Jul 24, 2013 @ 17:15
    Devin
    0

    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?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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>
    <xsl:for-each select="$currentPage/ancestor-or-self::*[@isDoc]/descendant-or-self::*[@isDoc]/*[@isDoc and string(showInFooter) = '1']">
                    <li>                    
                        <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:value-of select="@nodeName" />
                        </a>
                    </li>
                </xsl:for-each>
    </ul>
    </xsl:template>

    </xsl:stylesheet>

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jul 25, 2013 @ 08:21
    Chriztian Steinmeier
    0

    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

  • Devin 87 posts 251 karma points
    Jul 25, 2013 @ 10:34
    Devin
    0

    Thank you Chriztian that was exactly what I was looking for!

    If I wanted to add another level, would I just change:

    <xsl:variablename="siteRoot"select="$currentPage/ancestor-or-self::*[@level = 1]"/>

    to this?

    <xsl:variablename="siteRoot"select="$currentPage/ancestor-or-self::*[@level = 2]"/>
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jul 25, 2013 @ 10:43
    Chriztian Steinmeier
    1

    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.:

    <xsl:variable name="subPages" select="descendant::*[@isDoc][showInFooter = 1][@level &lt;= 4]" />

    - 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

  • Devin 87 posts 251 karma points
    Jul 25, 2013 @ 11:28
    Devin
    0

    Thank you kindly for your help. That makes perfect sense and was exactly what I wanted to do. :

  • 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.

Please Sign in or register to post replies