We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13736
    • 345 Posts
    Maybe I’m searching for the wrong terms, because it’s hard for me to imagine that no one has done this before.

    How do I create separate multi-level menu’s with Wayfinder. For example I have a top level menu that stays visible always (easy to do).

    Home | Products | Downloads | Contact Us

    If I click on "Products" I want the product page to load a secondary horizontal menu further down the page like maybe...

    Fruit | Vegetables | Meats | Grains

    Then if I were to click on "fruit" I want the fruit page to load a vertical menu on the page like...

    Apples
    Oranges
    Pears
    Grapes


    How can I make this an automatic process?

      • 7231
      • 4,205 Posts
      Here is an example that is on the current site I am working on with a main nav and a separate subnav. I have one template in two languages and it automatically loads the correct menu.

      Main nav:
      [!Wayfinder? &startId=`[[UltimateParent?]]` &level=`1` &outerTpl=`main_nav_tpl`!]


      This gets the UltimateParent one level down from the top which in my site is the root for each language like so

      root
      -EN
      --english content...
      -DE
      --german content

      And for the submenu I am using SectionRoots snippet so that I can choose the root levels. I could have used the UltimateParent with a level of 2 but I chose to go with sectionRoots (don’t remember exactly why at the moment, on other sites I have used ultimateparent or parent for all menus.
      [!Wayfinder? &startId=`[[SectionRoots?Sec_roots=3,4,5,6,7,8,10,11]]` &level=`5` &displayStart=`TRUE` &startItemTpl=`subnav_startItemTpl`!]


      With these two calls I am able to have the main menu and all the sub menus in my site. Hope this helps.

      One thing that wayfinder needs to work well is the site structure in the document tree. It depends on the container document relationship in order to work right. So you need to structure the site document tree in a logic that will make the parent principal work.

      So in your example the tree would need to be like this to be able to benifit from the parent document ralationship to build automated menus in wayfinder:

      Home
      Products
      -Fruit
      ---Apples
      ---Oranges
      ---Pears
      ---Grapes
      -Vegetables
      -Meats
      -Grains
      Downloads
      Contact Us
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 13736
        • 345 Posts
        So, does that mean there is currently no known way to do this automatically? I would like to avoid having to type in all the numbers for section roots. At three levels deep that could end up being dozens of numbers to keep track of and update if a new category is created.

        I tried the Ultimate parent snippet also, but unless I got something wrong, it seems to count backwards (from the current document upwards) rather than counting from the top down.
          • 7231
          • 4,205 Posts
          As for UltimateParent, I think it moves up from the current document.

          // Travels up the document tree from the current document
          // to return the "ultimate" parent

          UltimateParent may not be the best option for your objective. To get the ID of the current parent you can simply use [*parent*].

          [!Wayfinder? &startId=`[*parent*]` &level=`1`!]
          Will always return the menu for the section you are in. The catch is that it will not work in the container page itself (the container has a different parent than the subs) but in every subpage it will.

            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don't know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 29181
            • 480 Posts
            If you always want the third element in the hierachy maybe you could say:

            [[Wayfinder? &startId=`[!UltimateParent? &topLevel=`3`!]` &level=`1`]]

            It could be worth trying that UltimateParent call on its own somewhere to see if it’s returning the correct results.

            Maybe create a snippet that checks if the parents parent has the id of zero (or 1) as an alternative.

            Hope that helps,
            Taff
              Adrian Lawley: www.adrianlawley.com
              • 13736
              • 345 Posts
              Ok. I’ve done a little more experimenting. Using the UltimateParent tag inside WayFinder like this:

              [!Wayfinder? &startId=`[[UltimateParent? &topLevel=`2`]]` &level=`1`!]
              [!Wayfinder? &startId=`[[UltimateParent? &topLevel=`3`]]` &level=`1`!]
              


              does calculate from the top down. But the problem I’m having is if you are above the toplevel specified it returns the current document ID instead of returning nothing.

              So I need to figure out a way to only show the WayFinder menu as each level is reached. As it is now, if I’m sitting on a level 2 page I’ll get duplicate items from level 2 in the level 3 menu space.

                • 10449
                • 956 Posts
                I usually simply make one template (or chunk) per level (depth). That way I can always just refer to the parent and the containing children.
                  • 29181
                  • 480 Posts
                  You could integrate that UltimateParent call into another snippet that just tests if the result is equal to the current document ID, if so return nothing.

                  An alternative would be to duplicate the UltimateParent and change that part to return nothing. A quick glance at the snippet would imply that removing

                  if($pid[’id’] == $top) { return $id; }

                  would alter the snippet to return that type of functionality. I didn’t test it though (or look properly though wink)

                  Taff
                    Adrian Lawley: www.adrianlawley.com
                    • 26492
                    • 9 Posts
                    Quote from: Taff at Oct 06, 2007, 12:25 PM

                    You could integrate that UltimateParent call into another snippet that just tests if the result is equal to the current document ID, if so return nothing.

                    An alternative would be to duplicate the UltimateParent and change that part to return nothing. A quick glance at the snippet would imply that removing

                    if($pid[’id’] == $top) { return $id; }

                    would alter the snippet to return that type of functionality. I didn’t test it though (or look properly though wink)

                    Taff
                    I’m trying something like this on my site (and it seems to be the answer), but the code in the UltimateParent snippet that came with MODx is different. My menu has 4 levels (may increase later),and I have used the following lines:
                    <div id="menu">
                    [!Wayfinder? &startId=`0` &level=`1`!]</div>
                    
                    <div id="menu">
                    [!Wayfinder? &startId=`[[UltimateParent? &topLevel=`1`]]` &level=`1` &hideSubMenus=`1`!]</div>
                    
                    <div id="menu">
                    [!Wayfinder? &startId=`[[UltimateParent? &topLevel=`2`]]` &level=`1` &hideSubMenus=`1`!]</div>
                    
                    <div id="menu">
                    [!Wayfinder? &startId=`[[UltimateParent? &topLevel=`3`]]` &level=`1` &hideSubMenus=`1`!]</div>

                    Can anyone advise what I should do with UltimateParent to hide the sub-menus when the parent document is the current document? An example of the problem is on this page: http://www.50000freewallpapers.com/modx/index.php?id=2 - you can see that the lower levels of the menu are shown 3 times. The UltimateParent code I am using is:
                    <?php
                    
                    $top= isset ($top) && intval($top) ? $top : 0;
                    $id= isset ($id) && intval($id) ? intval($id) : $modx->documentIdentifier;
                    $topLevel= isset ($topLevel) && intval($topLevel) ? intval($topLevel) : 0;
                    if ($id && $id != $top) {
                        $pid= $id;
                        if (!$topLevel || count($modx->getParentIds($id)) >= $topLevel) {
                            while ($parentIds= $modx->getParentIds($id, 1)) {
                                $pid= array_pop($parentIds);
                                if ($pid == $top) {
                                    break;
                                }
                                $id= $pid;
                                if ($topLevel && count($modx->getParentIds($id)) < $topLevel) {
                                    break;
                                }
                            }
                        }
                    }
                    return $id;
                    ?>


                    I still have to work on the CSS to separate the menu levels & tidy up the page, but it seems that, once the repeating submenu problem is fixed, I might finally have a solution to a problem that has vexed me for days.