Copied to clipboard

Flag this post as spam?

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


  • ianhoughton 281 posts 605 karma points c-trib
    Jun 19, 2010 @ 17:55
    ianhoughton
    0

    Help with COGworks navigation package

    I've implemented the Cogworks navigation as a vertical side menu, which is working well but I cant seem to get the children pages to disappear.

    These are the Macro settings:

    <umbraco:Macro ID="Macro1" runat="server" Alias="[COG]Navigation" startingLevel="2" recurse="0" selectBranches="1" maxMenuDepth="1" ulBaseClass="vertical" branchClass="branch" selectedClass="selected" expandChildren="1" forceHome="0" forceNode="1084" />

    It doesn't matter where you are in the site, the children pages are always visible. The only difference in the XSLT code is a flag to check if a page is visible in the side navigation.
    This is the XSLT:
    <?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"
        exclude-result-prefixes="msxml umbraco.library">
    
    <xsl:output method="html" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage" />
    
    <!--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>
    <xsl:variable name="forceNode" select="/macro/forceNode"></xsl:variable>
    <xsl:variable name="walkChildren" select="/macro/expandChildren"></xsl:variable>
    <xsl:variable name="forceHome" select="/macro/forceHome"></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>
    
    <xsl:variable name="startLevel">
      <xsl:choose>
        <xsl:when test="$startDepth >= 0">
          <xsl:value-of select="$startDepth"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$currentPage/@level"/>
        </xsl:otherwise>
      </xsl:choose>
    </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:choose>
        <xsl:when test="$forceNode">
          <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById($forceNode)"></xsl:variable>
          <xsl:call-template name="nodeIterator">
            <xsl:with-param name="parentNode" select="$currentNode/ancestor-or-self::node[@level=$startLevel] [string(data [@alias='umbracoNaviHide']) != '1']" />
            <xsl:with-param name="pseudoCurrentPage" select="$currentNode" />
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:variable name="currentNode" select="$currentPage"></xsl:variable>
          <xsl:call-template name="nodeIterator">
            <xsl:with-param name="parentNode" select="$currentNode/ancestor-or-self::node[@level=$startLevel] [string(data [@alias='umbracoNaviHide']) != '1']" />
            <xsl:with-param name="pseudoCurrentPage" select="$currentNode" />
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
    
    <xsl:template name="nodeIterator">
        <xsl:param name="parentNode" />
        <xsl:param name="pseudoCurrentPage" />
        <!-- do not show info doc node types-->
    
      <xsl:variable name="calculatedMenuDepth" select="($parentNode/@level - $startLevel)+1" />
    
      <ul>
    
            <xsl:attribute name="class">
              <xsl:choose>
                <xsl:when test="$calculatedMenuDepth = 1">
                  <xsl:value-of select="concat($ulBaseClass, ' lv', $calculatedMenuDepth)" />
                </xsl:when>
                <xsl:when test="$calculatedMenuDepth > 1">
                  <xsl:value-of select="concat('lv', $calculatedMenuDepth)" />
                </xsl:when>
              </xsl:choose>
            </xsl:attribute>
    
            <xsl:if test="$forceHome = 1 and $calculatedMenuDepth = 1">
              <!-- Create the class for the li element-->
              <li>
                <xsl:attribute name="class">
                  <xsl:if test="$currentPage/ancestor-or-self::node[@level=1]/@id = $currentPage/@id">
                    <xsl:value-of select="concat($selectedClass,' ')"/>
                  </xsl:if>
                  <xsl:value-of select="'hasChildren '"/>
                </xsl:attribute>
    
                <a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node[@level=1]/@id)}">
    
                  <xsl:attribute name="class">
                    <xsl:if test="$currentPage/ancestor-or-self::node[@level=1]/@id = $currentPage/@id">
                      <xsl:value-of select="concat($selectedClass,' ')"/>
                    </xsl:if>
                  </xsl:attribute>
    
                  <!--set the innerText for the a element-->
                  <xsl:value-of select="$currentPage/ancestor-or-self::node[@level=1]/text()"/>
    
                  <xsl:if test="string($currentPage/ancestor-or-self::node[@level=1]/text()) = ''">
                    <xsl:value-of select="$currentPage/ancestor-or-self::node[@level=1]/@nodeName"/>
                  </xsl:if>
                </a>
              </li>
            </xsl:if>
            <!--End force home-->
    
    
            <!--for each node in the parent node that is not hidden by Umbraco-->
            <xsl:for-each select="$parentNode/node [string(data [@alias='umbracoNaviHide']) != '1' and string(data [@alias='showInSideNavigation']) = '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 and is it 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>
    
              <xsl:variable name="isSelectedBranch">
                <xsl:choose>
                  <xsl:when test="$isBranch = 1 and $selectBranches = 1">1</xsl:when>
                </xsl:choose>
              </xsl:variable>
    
              <xsl:variable name="hasChildren">
                <xsl:choose>
                  <xsl:when test="./node">1</xsl:when>
                </xsl:choose>
              </xsl:variable>
    
              <li>
    
                <!-- Create the class for the li element-->
                <xsl:attribute name="class">
                  <xsl:if test="$isSelected = 1"> <xsl:value-of select="concat($selectedClass,' ')"/> </xsl:if>
                  <xsl:if test="$isSelectedBranch = 1"> <xsl:value-of select="concat($branchClass,' ')"/> </xsl:if>
                  <xsl:if test="$hasChildren = 1"><xsl:value-of select="'hasChildren '"/></xsl:if>
                </xsl:attribute>
    
                <a href="{umbraco.library:NiceUrl(@id)}">
    
                  <xsl:attribute name="class">
                    <xsl:if test="$isSelected = 1"> <xsl:value-of select="concat($selectedClass,' ')"/> </xsl:if>
                    <xsl:if test="$isSelectedBranch = 1"> <xsl:value-of select="concat($branchClass,' ')"/> </xsl:if>
                  </xsl:attribute>
    
                  <!--set the innerText for the a element-->
                  <xsl:value-of select="./data[@alias='contentPageTitle']/text()"/>
    
                    <xsl:if test="string(./data[@alias='contentPageTitle']/text()) = ''"> 
                      <xsl:value-of select="@nodeName"/>
                  </xsl:if>
                </a>
    
                <!-- if it's a branch recurse through it's children -->
                <xsl:if test="((($isBranch = 1 and $recurse = 1) or ($walkChildren = 1 and $currentPage/descendant-or-self::node[@id = $currentNodeID]/child::node)) and $maxMenuDepth &gt;= $calculatedMenuDepth)">
           <!-- <xsl:if test="((($isBranch = 1 and $recurse = 1) or ($walkChildren = 1)) and $maxMenuDepth &gt;= $calculatedMenuDepth)"> -->
                  <xsl:call-template name="nodeIterator">
                    <xsl:with-param name="parentNode" select="." />
                    <xsl:with-param name="pseudoCurrentPage" select="$pseudoCurrentPage" />
                  </xsl:call-template>
                </xsl:if>
              </li>
    
            </xsl:for-each>
    
          </ul>
      </xsl:template>
    
    </xsl:stylesheet>

  • Tim 225 posts 690 karma points
    Jun 23, 2010 @ 00:24
    Tim
    0

    Hi,

    I'm not 100% what effect you are trying to acheive or what the structure of your pages are however you have the expandChildren property set to 1. If you set this to 0 it will not show the child nodes.

    This (along with your current settings) will keep the navigation static so that it will always show the same thing no matter where you are in the site.

    Tim

     

  • León van de Pavert 15 posts 37 karma points
    Aug 10, 2010 @ 14:29
    León van de Pavert
    0

    At the bottom of the nodeIterator xsl:template

    <!-- If it's a branch and recurse through it's children -->
    <xsl:if test="((($isBranch = 1 and $recurse = 1) or ($walkChildren = 1 and $currentPage/descendant-or-self::node[@id = $currentNodeID]/child::node)) and $maxMenuDepth &gt;= $calculatedMenuDepth)">

    only expands the menu tree if a parent of a branch or a child in branch is selected. It does not expand an unselected branch.

    However, if we want the entire tree to expand, replacing

    $walkChildren = 1 and ...

    with

    ($walkChildren = 1 and $hasChildren = 1) or ...

    gives a possibility to always expand the entire menu tree based on the value of $walkChildren=1 and only showing the selected branch when $walkChildren=0. Proper CSS :hover statements or JavaScript could now expand and collapse the menu in a more dynamic way.

    Regards,
    León

  • Neil Norpa 24 posts 44 karma points
    Jun 22, 2011 @ 13:23
    Neil Norpa
    0

    I have implemented the nav but i have an issue due to the children using the selected css class, when they are not selected.

    <umbraco:Macro startingLevel="2" recurse="1" selectBranches="0" maxMenuDepth="999" ulBaseClass="parent-list" branchClass="" selectedClass="current" securityTrimming="1"  Alias="[COG]Navigation" runat="server"></umbraco:Macro>
            <!--<li class="l1"><a href="/">Human resources and payroll (level 1)</a></li>

    source output

            <ul class="parent-list lv1">
      <li class="current hasChildren"><a href="/about-us/vision,-mission-and-values.aspx" class="current">Vision, mission and values</a><ul class="lv2">
          <li class="hasChildren"><a href="/about-us/vision,-mission-and-values/child-1-test.aspx">child 1</a></li>
          <li><a href="/about-us/vision,-mission-and-values/side-navy.aspx">side navy</a></li>
        </ul>

    i think its basically down to the selected class bering current has Children instead of just current.

     

    Any ideas


     

Please Sign in or register to post replies

Write your reply to:

Draft