Copied to clipboard

Flag this post as spam?

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


  • Vincent DeCapite 64 posts 83 karma points
    Nov 23, 2010 @ 13:32
    Vincent DeCapite
    0

    XSLT Navigation Footer

    Hi There,

    Hopefully I can get some help with this... We picked up a website that one of our vendors created and we need to change the footer navigation. The template that is in place now is this:

    <?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:fn="urn:Exslt.ExsltStrings"
     exclude-result-prefixes="fn msxml umbraco.library">
       
       
      <xsl:output method="html" omit-xml-declaration="yes" indent="yes"/>
      <xsl:param name="currentPage"/>
      <!-- Get parameters from Macro -->
      <xsl:param name="location" select="/macro/location"/>
      <xsl:param name="level" select="/macro/level"/>
      <xsl:param name="css" select="/macro/css"/>
      <xsl:param name="ancestorAlias" select="/macro/ancestorAlias"/>
      <xsl:param name="nodeID" select="/macro/nodeID"/>
     
      <!-- Set some variables -->
      <xsl:variable name="startNode">
       <xsl:choose>
         <xsl:when test="$nodeID != ''">
             <xsl:copy-of select="$currentPage/ancestor-or-self::node [@level=1]//node[@id=$nodeID]"/>
            </xsl:when>
         <xsl:when test="$ancestorAlias != ''">
             <xsl:copy-of select="$currentPage/ancestor-or-self::node[@nodeTypeAlias=$ancestorAlias]"/>
            </xsl:when>
            <xsl:otherwise>
             <xsl:copy-of select="$currentPage/ancestor-or-self::node [@level=1]" />
            </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="maxLevel">
       <xsl:choose>
            <xsl:when test="$level=0">
             <xsl:value-of select="0"/>
            </xsl:when>
         <xsl:when test="$level != ''">
             <xsl:value-of select="$level + msxml:node-set($startNode)/node/@level"/>
            </xsl:when>
            <xsl:otherwise>
             <xsl:value-of select="msxml:node-set($startNode)/node/@level + 1" />
            </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      
      <!-- Begin Template -->
      <xsl:template match="/">
       <xsl:if test="msxml:node-set($startNode)//node [(string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevel and contains(fn:lowercase(data [@alias='pageNavigation']), fn:lowercase($location))) or $maxLevel=0]" >
        <ul>
          <xsl:if test="$css != ''">
           <xsl:attribute name="class">
             <xsl:value-of select="$css" />
            </xsl:attribute>
          </xsl:if>
          <xsl:choose>
           <xsl:when test="$maxLevel=0">
              <xsl:call-template name="drawNodesAll">
                  <xsl:with-param name="parent" select="msxml:node-set($startNode)/node"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="drawNodes">
                <xsl:with-param name="parent" select="msxml:node-set($startNode)/node"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </ul>
        </xsl:if>
      </xsl:template>
     
      <xsl:template name="drawNodes">
        <xsl:param name="parent"/>
        <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevel and contains(fn:lowercase(data [@alias='pageNavigation']), fn:lowercase($location))]">
          <li>
           <xsl:attribute name="class">
             <xsl:text>navigation_</xsl:text>
             <xsl:value-of select="@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:text> selected</xsl:text>
                </xsl:if>
            </xsl:attribute>
            <xsl:apply-templates select="." />        
            <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevel and contains(fn:lowercase(./data [@alias='pageNavigation']), fn:lowercase($location))]) &gt; 0 ">
              <ul>
                <xsl:call-template name="drawNodes">
                  <xsl:with-param name="parent" select="."/>
                </xsl:call-template>
              </ul>
            </xsl:if>
          </li>
        </xsl:for-each>
      </xsl:template>
      <xsl:template name="drawNodesAll">
        <xsl:param name="parent"/>
        <xsl:for-each select="$parent//node [string(./data [@alias='umbracoNaviHide']) != '1' and contains(fn:lowercase(data [@alias='pageNavigation']), fn:lowercase($location))]">
          <li>
           <xsl:attribute name="class">
             <xsl:text>navigation_</xsl:text>
             <xsl:value-of select="@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:text> selected</xsl:text>
                </xsl:if>
            </xsl:attribute>
            <xsl:apply-templates select="." />        
          </li>
        </xsl:for-each>
      </xsl:template>
      <xsl:template match="node" name="drawLink">
            <a>
      <xsl:choose>
                <xsl:when test="string(./@nodeTypeAlias) = 'externalLink'">
                 <xsl:attribute name="href">
                     <xsl:value-of select="./data [@alias='URL']" />
                    </xsl:attribute>
                    <xsl:attribute name="target">_blank</xsl:attribute>
                </xsl:when>
       <xsl:when test="string(./data [@alias='target']) != ''">
                 <xsl:attribute name="target">
                     <xsl:value-of select="./data [@alias='target']" />
                    </xsl:attribute>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:attribute name="href">
                     <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
                    </xsl:attribute>
                </xsl:otherwise>
            </xsl:choose>
            <!-- Add the display name -->
            <xsl:choose>
             <xsl:when test="string(./data [@alias='pageNavigationName']) != ''">
                 <xsl:value-of select="./data [@alias='pageNavigationName']"/>
                </xsl:when>
                <xsl:otherwise>
                 <xsl:value-of select="@nodeName"/>
                </xsl:otherwise>
            </xsl:choose>
      </a>        
      </xsl:template>
    </xsl:stylesheet>

    What the user does now is in every page, there is 2 check boxes that say Top or bottom navigation with an ID of pageNavigation. The problem is, the user can't control this dynamically, and they can't reorder it to however they want. I was wondering if anyone had any ideas about how to either allow them to choose the pages that are allowed to be in the footer, and be able to specify the order.

     

    Any help would be greatly appreciated.. Thanks

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 23, 2010 @ 13:50
    Matt Brailsford
    0

    Hey Vincent,

    Not sure what you mean by they "can't control this dynamically"? Can't they just check the checkbox to say "show in footer nav"?

    RE the ordering, it looks like it orders things in the natural order they appear, so technically you do have control over the sorting, you can just sort the nodes in the node tree, and they will appear in that order (This is generally a pretty normal way to achive this).

    If you require them sorting by some other means, you could do an XSLT sort if you just need them alphabetically. If you need them in such an order that they differ between the main and footer nav, then yea, you are going to have to do a little more work. A simple way could be to just drop a "sortIndex" property onto all your templates, then do an XSLT sort on that, but it could get a little dificuilt to manage if you have a few nodes.

    Many thanks

    Matt

  • Rich Green 2246 posts 4008 karma points
    Nov 23, 2010 @ 13:57
    Rich Green
    0

    Hi Vincent,

    You can order and pick content with the tree multipicker http://our.umbraco.org/projects/backoffice-extensions/tree-multi-picker

    The rough idea being that you have two, one for header and one for footer, there would only be one of each of these in your whole site (probably on the home node or it a settings section)

    You then use the id's selected in the tree picker to display the links in the footer, the order the user selected will remain in tack.

    Rich

  • Vincent DeCapite 64 posts 83 karma points
    Nov 23, 2010 @ 13:59
    Vincent DeCapite
    0

    Many Thanks For the quick reply Matt... I get what your saying the one thing that I am running into is that we have different pages on our website, and sub pages under those. The problem is, is that there is a page on the second level navigation that we want to show in the footer. When we click the Show in footer nav, it doesn't show. i was playing around with the levels in the code changing them from 1 level to 2, but then that toally messes up the result.. Does that make any sense?

  • Rich Green 2246 posts 4008 karma points
    Nov 23, 2010 @ 14:06
    Rich Green
    0

    Didn't see Matt's reply before I posted.

    I think there are two things going on, your main top navigation, and some links in the footer which the user can choose and order, is that correct?

    I didn't have time to read through your code but as Matt rightly states navigation is usually presented in the order it lives in Umbraco.

    I wouldn't use my suggestion of using the tree picker for your top nav (I misunderstood your post) but the for the footer it should work fine.

    Rich

     

  • Vincent DeCapite 64 posts 83 karma points
    Nov 23, 2010 @ 14:09
    Vincent DeCapite
    0

    This is correct.. Matt's suggestion does work.. The other problem I am running into is with the different levels.. For instance, under an main heading navigation, there is a link that links to a quality page. I want just that second level to show in the footer navigation. The problem is with the levels in the code. I tried playing with the Maxlevel chaning it to 1, and the other levels changing it to 2. No matter, what I do, I cannot get the sub page to show in the footer. if i change the level to 2, I lose the main navigation and just get the second level navigation.. Does that make any sense?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 23, 2010 @ 14:12
    Matt Brailsford
    0

    Hey Vincent,

    Looking at the script, it seems like it can run in 2 modes.

    If you set the level to 0, it should just return a list of links who are set to display in the footer as a flat list.

    If you set the level to something greater than 0, then it'll create a tree type structure. If this is what structure you need, then you'll need to set level to be greater than or equal to the depth of the item you want to show, but will also need to see the ancesters of that item to also show in the footer (You can't show a child node, if it's parent isn't visible aswell).

    Without knowing exactly what you are trying to output, it's a bit hard to say what you should do exactly, but I'd certainly have a play around this area.

    If you want to replace that functionality completley with something with a bit more control, then I'd take a look at Rich's suggestion.

    Matt

  • Vincent DeCapite 64 posts 83 karma points
    Nov 23, 2010 @ 14:18
    Vincent DeCapite
    0

    Its acting a little funny. If I change this piece of code:

      <xsl:variable name="maxLevel">
       <xsl:choose>
            <xsl:when test="$level=0">
             <xsl:value-of select="0"/>
            </xsl:when>
         <xsl:when test="$level != ''">
             <xsl:value-of select="$level + msxml:node-set($startNode)/node/@level"/>
            </xsl:when>
            <xsl:otherwise>
             <xsl:value-of select="msxml:node-set($startNode)/node/@level + 1" />
            </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

    If I change that variable to a 2, i get the tree notion. If i change that to a 0 i get no navigation what so ever.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Nov 23, 2010 @ 14:20
    Matt Brailsford
    0

    Hi Vincent,

    That is to be expected, as that is the maxLevel variable you are modifying, so no nodes exist at level 0, so won't display. The level variables looks to be defined as a macro paramater which get's passed in. Have you tried modiying that?

    Matt

  • Vincent DeCapite 64 posts 83 karma points
    Nov 23, 2010 @ 14:23
    Vincent DeCapite
    0

    Yes.. I have, no luck, if i am looking in the right place for it.

  • Vincent DeCapite 64 posts 83 karma points
    Nov 23, 2010 @ 14:37
    Vincent DeCapite
    0

    Thanks all for the help.. I was able to figure it out.. The piece of code that needed to be changed was

    <

     

    xsl:choose>

    <

     

    xsl:when test="$maxLevel=2">

    <

     

    xsl:call-template name="drawNodesAll">

    <

     

    xsl:with-param name="parent" select="msxml:node-set($startNode)/node"/>

    </

     

    xsl:call-template>

    </

     

    xsl:when>

    There was a 1 where the 2 was.. AS soon as that was changed it worked beautifully.. Hope this can help someone else.. Thanks again.

Please Sign in or register to post replies

Write your reply to:

Draft