Copied to clipboard

Flag this post as spam?

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


  • ashwini 43 posts 63 karma points
    May 11, 2012 @ 15:59
    ashwini
    0

    How to make the header navigation stay the same ?

    Good Morning everyone,

    I am very new to umbraco and i am staill struggling to learn the basics. I am working on a site that was developed my someone else couple of months ago. I have come across the navigation problem. The structure of the site is like this:

    And the code for the navigation in the xslt files is like this:

    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>            
         <class="navigation" href="{umbraco.library:NiceUrl(@id)}">
          <span><xsl:value-of select="@nodeName"/></span>
        </a
      </li

    My problem:

    I want the header to always display the contents or the nodes in simple website, however when i click on a page which come from *news folder, the header changes to the nodes names from that particular folder. How do i make sure that the header navigation stays the same no matter which page i click ?

    Would i have to restructure my enitre contents ?

    Please advise !

    Thanks 

     

  • ashwini 43 posts 63 karma points
    May 11, 2012 @ 16:03
    ashwini
    0

    the entire code:

     <xsl:output method="xml" omit-xml-declaration="yes" />

        <xsl:param name="currentPage"/>

        <!-- Input the documenttype you want here -->
        <xsl:variable name="level" select="1"/>

        <xsl:template match="/">

          
     <ul id="topNavigation">
           <li class="home">
             <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
                 <xsl:attribute name="class">home current</xsl:attribute>
             </xsl:if>
             <href="/">Home</a>
             
           </li>
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
                        
         <class="navigation" href="{umbraco.library:NiceUrl(@id)}">
          <span><xsl:value-of select="@nodeName"/></span>
        </a
          
           </li
            
    </xsl:for-each>
         
    </ul>

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    May 12, 2012 @ 16:11
    Chriztian Steinmeier
    0

    Hi ashwini,

    This happens because the navigation looks for the ancestor at level 1 to be the root of the menu (which normally is the case - many Umbraco sites have a single root node containing the site nodes) - but when you're in the news section it'll obviously find the "### News" node instead - the trick here is to make sure to find the correct top node, which you can do by going all the way to the <root> element first, and then selecting the "Simple website" node relative to that instead. It also makes everything much easier to read (and modify):

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="umbraco.library"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    <!-- Go all the way up to the <root> containg everything --> <xsl:variable name="absoluteRoot" select="$currentPage/ancestor::root" />
    
        <!-- You can do this one by @id too, if you want e.g.: $absoluteRoot/*[@id = 1234] -->
        <xsl:variable name="simpleSiteRoot" select="$absoluteRoot/*[@nodeName = 'Simple website']" />
    
        <xsl:template match="/">
            <ul id="topNavigation">
                <li class="home">
                    <xsl:if test="$currentPage/@id = $simpleSiteRoot/@id">
                        <xsl:attribute name="class">home current</xsl:attribute>
                    </xsl:if>
                    <a href="/">Home</a>
                </li>
                <xsl:for-each select="$simpleSiteRoot/*[@isDoc][not(umbracoNaviHide = 1)]">
                    <li>
                        <a class="navigation" href="{umbraco.library:NiceUrl(@id)}">
                            <span><xsl:value-of select="@nodeName" /></span>
                        </a>
                    </li> 
                </xsl:for-each>
            </ul>
        </xsl:template>
    
    </xsl:stylesheet>

    /Chriztian

  • ashwini 43 posts 63 karma points
    May 14, 2012 @ 15:42
    ashwini
    0

    wow ! thanks a lot Chriztian. The code worked perfetcly fine. I knew that it had to do something with the root level etc but i was not sure how to change it. I really appreciate your quick response...

Please Sign in or register to post replies

Write your reply to:

Draft