Copied to clipboard

Flag this post as spam?

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


  • trfletch 598 posts 604 karma points
    Jan 08, 2010 @ 16:44
    trfletch
    0

    Menu from certain node instead of top level

    Hopefully this will be a simple answer for someone. I have an Umbraco V4 site with the following XSLT for a menu, the only problem is this creates a menu from the top level of the site but I want to only show a menu from a certain node downwards. I assume I have to put something like this in:

    <xsl:for-each select="umbraco.library:GetXmlNodeById(**the node id**)/node [string(data [@alias='umbracoNaviHide']) != '1']">

    But I'm not quite sure where because I created this menu from the sitemap template so it is by default designed to list the whole site structure:

    <xsl:variable name="maxLevelForSitemap" select="5"/>
    <xsl:template match="/">
    <div id="sitemap">
    <ul class="sf-menu">
    <li><a href="/">home</a></li>
    </ul>
    <xsl:call-template name="drawNodes"> 
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/> 
    </xsl:call-template>
    </div>
    </xsl:template>
    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
    <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
    <ul class="sf-menu"><xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForSitemap]">
    <li><xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
      <xsl:attribute name="class">active-menu</xsl:attribute>
      </xsl:if>
    <xsl:choose>
    <xsl:when test="data [@alias = 'nomenulink'] ='1'">
    <a href="#">
    <xsl:value-of select="@nodeName"/></a>
    </xsl:when>
    <xsl:otherwise>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/></a>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="count(./node [string(./data [@alias='nestedmenuHide']) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">   
    <xsl:call-template name="drawNodes">   
    <xsl:with-param name="parent" select="."/>   
    </xsl:call-template> 
    </xsl:if>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

     

  • Rich Green 2246 posts 4008 karma points
    Jan 08, 2010 @ 17:15
    Rich Green
    1

    Try changing:

     

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/> 

    to

     

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=2]"/> 
  • trfletch 598 posts 604 karma points
    Jan 08, 2010 @ 17:26
    trfletch
    0

    Hi Rich,

    Thanks for the reply, I tried that but the trouble is depending what page I am on I get a different menu, this is because of the way that my site is structured as shown below. I need this menu to only show the links to the Main menu pages even if I am currently viewing one of the footer menu pages hence why I need to specify exactly where to create the menu from:

     

    Home
        - Main menu pages
              - Page 1
              - Page 2
       - Footer menu pages
             - Page 3
             - Page 4
       - Another page

     

  • Rich Green 2246 posts 4008 karma points
    Jan 08, 2010 @ 17:50
    Rich Green
    0

    Guessing here but try something like

     

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node[@nodeTypeAlias='Main Menu']"/>

    Rich

  • Rich Green 2246 posts 4008 karma points
    Jan 08, 2010 @ 17:54
    Rich Green
    0

    Just in case I wasn't clear

    replace

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/>

    with 

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node[@nodeTypeAlias='Main Menu']"/>

     

    Rich

  • trfletch 598 posts 604 karma points
    Jan 08, 2010 @ 18:03
    trfletch
    0

    Thanks for the reply, I tried that but it has an error parsing XSLT file. Any other suggestions?

  • Rich Green 2246 posts 4008 karma points
    Jan 08, 2010 @ 18:14
    Rich Green
    0

    Try clicking the Skip testing check box and saving.

    Rich

  • trfletch 598 posts 604 karma points
    Jan 08, 2010 @ 18:20
    trfletch
    0

    I have already done that, the xslt error is on the page.

  • Rich Green 2246 posts 4008 karma points
    Jan 08, 2010 @ 18:46
    Rich Green
    0

    Sorry brain's not working too well today,  someone will be along with another suggestion soon.

  • trfletch 598 posts 604 karma points
    Jan 11, 2010 @ 10:18
    trfletch
    0

    Ok, thanks for your help, is there anyone else with any suggestions on this?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 11, 2010 @ 10:37
    Chriztian Steinmeier
    0

    Hi trfletch,

    I'll try to help you out, but I need to be sure what you're expecting as output. Given your structure:

    Home
        - Main menu pages
              - Page 1
              - Page 2
       - Footer menu pages
             - Page 3
             - Page 4
       - Another page

    You only want links to "Page 1" and "Page 2" (+ any future additions to "Main menu pages"), regardless of $currentPage?

    /Chriztian

     

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Jan 11, 2010 @ 10:45
    Douglas Robar
    3

    Rich is right that you only need to change the following line:

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/>

    This is where the navigation/sitemap "starts" from.

    The select statement is basically saying... from whatever page the website visitor is viewing ($currentPage), go up the content tree (/ancestor) or use the current page if it already matches my requirements (-or-self), for any node (::node) WHERE (the square brackets are like a 'where' clause in sql if you're familiar with them) the node is at the first level of the content tree (@level = 1).

    Hope that makes some sense :)

    Anyway, the key is to change the bit within square brackets to meet your needs.

    You don't want to start at the first level since that will give everything in the content tree. You could try any of these options. I think they will all work but give them a try and choose your favorite.

    1. Hard-code the id of the 'Main menu pages' node, which you can find by hoving your mouse over that node in the content tree... that browser's status bar will show you it's id number. Your code would then look like this (assuming the id were 1234 in my example... update as appropriate):

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@id = 1234]"/>

    2. Only go to level 2, since your Main menu pages node is at that level (the Home node is at level 1 according to your description)

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=2]"/>

    3. Look for a unique document type (aka, @nodeTypeAlias). If your Main menu pages node is a unique document type you can look for it by its type rather than its id or where it exists in the content tree. Depending on how you built your site this might or might not be the case. But if it *is* unique you could do something like this (assuming the document type alias is 'MainMenuHolder' in my example... update as appropriate):

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'MainMenuHolder']"/>

    Be aware that this option won't work if the node doesn't have a unique document type associated with it.

     

    At least one of those options should work for you. If not, tell us what was returned from each and that should help us find the right solution for you.

    cheers,
    doug.

  • trfletch 598 posts 604 karma points
    Jan 11, 2010 @ 11:11
    trfletch
    0

    Hi Doug,

    Thank you for the quick and detailed response, I have tried all three methods you suggested and each one has the following error when trying to save the XSLT:

    (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, IList`1 parent) 
    at

    (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

    And if I select skip testing then they all have the following error on the page:

    Error parsing XSLT file: \xslt\nested-menu.xslt 

    Any ideas as to why this could be happening?

  • trfletch 598 posts 604 karma points
    Jan 11, 2010 @ 16:52
    trfletch
    0

    Chriztian,

    Sorry, only just seen your response. Yes that is correct, I only want links to Page 1 and 2 regardless of where you are in the site.

  • trfletch 598 posts 604 karma points
    Jan 12, 2010 @ 16:11
    trfletch
    0

    Thanks for everyone's help on this one, I have managed to solve it for myself with the following change, I was pointed in the right direction by Doug and Rich. The change I made is as follows:

    <xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById(1068)"/>  
  • Ronnie 3 posts 23 karma points
    Jan 22, 2010 @ 09:50
    Ronnie
    0

    Chriztian Steinmeier:

    Thats exactly what i want to do!

    Do you have a solution for that?

     

    Regards

    \\Ronnie

  • trfletch 598 posts 604 karma points
    Jan 22, 2010 @ 10:30
    trfletch
    0

    Hi Ronnie,

    What is it you want to do? The method I used has worked for me, let me know if you want an explanation

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 22, 2010 @ 10:50
    Chriztian Steinmeier
    0

    Hi Ronnie (+ others)

    You can use the built-in XSLT template "List Subpages From A Changeable Source", where you add a contentPicker parameter to the macro. (Check the comment in the XSLT source for the correct name of the parameter.)

    /Chriztian

     

  • Ronnie 3 posts 23 karma points
    Jan 22, 2010 @ 11:25
    Ronnie
    0

    Hello lads

    My layout looks as follows

    HOME

    File

    File

    File

    and i want to use HOME as index on the website, but i dont want it showing as meny item,

     

    //Ronnie

     

  • Ronnie 3 posts 23 karma points
    Jan 22, 2010 @ 11:53
    Ronnie
    0

    Chriztian Steinmeier

    Solved easily with your Suggestion

    Thank you everyone

    Regards

    \\Ronnie

Please Sign in or register to post replies

Write your reply to:

Draft