Copied to clipboard

Flag this post as spam?

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


  • Joe 21 posts 41 karma points
    Feb 10, 2011 @ 20:44
    Joe
    0

    Secondary Nav - Exclusion Help

    What I Need: My secondary nav to output only the page titles below Software, Applications, Related Products, Our Clients, and Support.  So, when I click on the Software link from the main nav, a <ul> populated with all page titles below Software should appear below the Software link.  Really, I just want to exclude Home from having a <ul> of second level titles created because it will populate a list that is already seen in the main nav.

    Folder Setup:

     

    My Secondary Level Nav Code:

     

    <?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="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1'and @nodeTypeAlias!='Home']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 10, 2011 @ 21:26
    Jan Skovgaard
    0

    Hi Joe

    Is this sample how your primary navigation looks?

    If you go to the developer section and create a new XSLT based macro you should be able to choose the "Navigation prototype" from the dropdown. Here you'll find a level macro where you can specify the levels that should be displayed in your secondary navigation.

    I think this should solve your issue? :-)

    /Jan

  • Jason Prothero 422 posts 1243 karma points MVP c-trib
    Feb 10, 2011 @ 22:07
    Jason Prothero
    0

    Is the Document Type of the home page "Home"?

    Or are you trying to check for the name of the node (@nodeName)?

  • Joe 21 posts 41 karma points
    Feb 10, 2011 @ 22:35
    Joe
    0

    Thanks for the responses guys!

    The image sample above is my current  folder configuration in umbraco.  The source code above is for the secondary nav that I haven't implemented yet.

    Here is how that folder setup renders with my main nav:



    Here is the source code for my main nav:

    <?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="xml" omit-xml-declaration="yes" />

    <xsl:param name="currentPage"/>

    <!-- 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 -->

    <!--xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']"-->
    <xsl:for-each select="umbraco.library:GetXmlNodeById(1045)/node [string(data [@alias='umbracoNaviHide']) != '1']">
            <a href="{umbraco.library:NiceUrl(@id)}" class="navOff">
                <xsl:choose>
                    <xsl:when test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                        <xsl:attribute name="class">navOn</xsl:attribute>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">navOff</xsl:attribute>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:value-of select="@nodeName"/>
            </a>
    <!-- Secondary Navigation Tests Here -->


    </xsl:for-each>


    </xsl:template>

    </xsl:stylesheet>


    What I am having trouble with is outputing the second level links below the first level links after the first level link is clicked.

    Does that make sense?

    @Jason - In the first code snippet I attached, I was trying to create a loop that would output second level nav links for all pages except Home.

     

    Hope this all makes sense - a lot of writing for something so simple! :]

  • Jason Prothero 422 posts 1243 karma points MVP c-trib
    Feb 11, 2011 @ 23:16
    Jason Prothero
    0

    Is the home page the 1045 id above?

     

     

  • Joe 21 posts 41 karma points
    Feb 11, 2011 @ 23:17
    Joe
    0

    Hi Jason

     

    Yes, that's right.

  • Jason Prothero 422 posts 1243 karma points MVP c-trib
    Feb 12, 2011 @ 00:19
    Jason Prothero
    0

    I made a small modification, but I'm not sure it will give you what you want.  Does that get close?

    <!--xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']"-->
    <xsl:for-each select="umbraco.library:GetXmlNodeById(1067)/node [string(data [@alias='umbracoNaviHide']) != '1']">
            <a href="{umbraco.library:NiceUrl(@id)}" class="navOff">
                <xsl:choose>
                    <xsl:when test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                        <xsl:attribute name="class">navOn</xsl:attribute>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">navOff</xsl:attribute>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:value-of select="@nodeName"/>
            </a>

    <xsl:variable name="parent" select="."/>

    <!-- Secondary Navigation Tests Here -->
    <ul>
    <xsl:for-each select="$parent/node [string(data [@alias='umbracoNaviHide']) != '1'and @nodeTypeAlias!='Home']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>
    </xsl:for-each>
    </ul>

    </xsl:for-each>

    Why can't you use the base Navigation starter macro (or even the Sitemap macro)?

     

    I've also used something like this to accomplish what you're trying to do.  Maybe this will help too.

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul class="headerNav sf-menu flt">
    <li>
    <xsl:attribute name="class">
        <xsl:if test="$currentPage/@nodeTypeAlias = 'HomePage'">
            current
        </xsl:if>
    </xsl:attribute>
    <a href="/">Home</a>
    </li>
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">

        <li>
                <xsl:attribute name="class">
                <xsl:if test="count(./descendant-or-self::node[@id = $currentPage/@id]) > 0">
                    current
                </xsl:if>
                </xsl:attribute>

            <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>                     

            <xsl:if test="count(./child::node) &gt; 0">
                <ul>
                    <xsl:for-each select="./child::node [string(data [@alias='umbracoNaviHide']) != '1']">
                        <li>
                            <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>                     

                        </li>
                    </xsl:for-each>
                </ul>   
            </xsl:if>
        </li>

    </xsl:for-each>
    </ul>

    </xsl:template>
  • Joe 21 posts 41 karma points
    Feb 15, 2011 @ 19:55
    Joe
    0

    @ Jason - Thanks for the reply :)

    I tried your first suggestion, and it was close, but there are a few issues.

    See the image below to see how it rendered.

    You'll notice how it displays all the list items at once. I am trying to make it work so that when I click on, let's say, Related Products, after the click is made, LiftTrainer, Physical Therapy, and SwingTrainer would appear.

    **Only the links with a carrot should appear when the Home page is first loaded.  **Secondary links should appear when their parent is clicked.

    Also, you can see that there are some indentation issues with the level one items (carrot links). Any idea why that would happen? They should all be left justified.

  • Jason Prothero 422 posts 1243 karma points MVP c-trib
    Feb 15, 2011 @ 20:22
    Jason Prothero
    0

    I think you probably need to change this:

                <xsl:if test="count(./descendant-or-self::node[@id = $currentPage/@id]) > 0">
                    current
               
    </xsl:if>

    To use your navOn/navOff classes

    Also, the secondary nav didn't take into account the umbracoNaviHide.  Try this:

            <xsl:if test="count(./child::node [string(data [@alias='umbracoNaviHide']) != '1']) &gt; 0">
               
    <ul>
                   
    <xsl:for-each select="./child::node [string(data [@alias='umbracoNaviHide']) != '1']">
                       
    <li>
                           
    <a href="{umbraco.library:NiceUrl(@id)}">
                                   
    <xsl:value-of select="@nodeName"/>
                           
    </a>                      

                       
    </li>
                   
    </xsl:for-each>
               
    </ul>    
           
    </xsl:if>

     

     

  • Joe 21 posts 41 karma points
    Feb 15, 2011 @ 22:51
    Joe
    0

    Nearly there! The only thing I'm having trouble with now is getting the secondary links to appear only when their parent is clicked. 

    You said

         <xsl:if test="count(./descendant-or-self::node[@id = $currentPage/@id]) > 0">
                    current
               
    </xsl:if>

    should be used to address the navOn/navOff classes.  Where exactly would that be placed?

    Here is the code that works nicely as a static list:

    <?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="xml" omit-xml-declaration="yes" />

    <xsl:param name="currentPage"/>

    <!-- 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 -->


    <xsl:for-each select="umbraco.library:GetXmlNodeById(1045)/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <a href="{umbraco.library:NiceUrl(@id)}" class="navOff">
    <xsl:choose>
    <xsl:when test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <xsl:attribute name="class">navOn</xsl:attribute>

    </xsl:when>
    <xsl:otherwise>
    <xsl:attribute name="class">navOff</xsl:attribute>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:value-of select="@nodeName"/>
    </a>
    <!-- Secondary Nav -->
    <xsl:if test="count(./child::node [string(data [@alias='umbracoNaviHide']) != '1']) &gt; 0">
    <ul>
    <xsl:for-each select="./child::node [string(data [@alias='umbracoNaviHide']) != '1']">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>

    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>

    <!-- Secondary Nav -->
    </xsl:for-each>


    </xsl:template>

    </xsl:stylesheet>

    So, now I just have to figure out how to hide the secondary links until their parent is clicked.

  • Joe 21 posts 41 karma points
    Feb 18, 2011 @ 17:23
    Joe
    0

    Any ideas on this one?  I still can't get the secondary links to appear only after their parent is clicked. They appear fine as a static list though.

    Thanks!

  • Jason Prothero 422 posts 1243 karma points MVP c-trib
    Feb 23, 2011 @ 19:55
    Jason Prothero
    0

    Sorry it took me a while to respond...

    How does this work for you?

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">

      <a href="{umbraco.library:NiceUrl(@id)}" class="navOff">
        <xsl:attribute name="class">
          <xsl:choose>
            <xsl:when test="count(./descendant-or-self::node[@id = $currentPage/@id]) > 0">
              <xsl:value-of select="'navOn'"/>                               
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="'navOff'"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:attribute>

        <xsl:value-of select="@nodeName"/>
      </a>
      <!-- Secondary Nav -->
      <xsl:if test="count(./child::node [string(data [@alias='umbracoNaviHide']) != '1']) &gt; 0">
        <ul>
          <xsl:for-each select="./child::node [string(data [@alias='umbracoNaviHide']) != '1']">
          <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:value-of select="@nodeName"/>
            </a>                     
          </li>
          </xsl:for-each>
        </ul>   
      </xsl:if>
      <!-- Secondary Nav -->

    </xsl:for-each>
Please Sign in or register to post replies

Write your reply to:

Draft