We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10313
    • 375 Posts
    Hello,

    I’m trying to use UltimateParent to generate a submenu with Wayfinder. Using the delivered version of ultimateParent in modX 0.9.6.

    This is my Wayfinder call:

    [!Wayfinder? &debug=`1` &startID=`[[UltimateParent]]` &hideSubMenus=`true` &outerClass=`leftmenu` &rowTpl=`wfRowTpl` &selfClass=`self`!]


    With debug I can see that UltimateParent always just returns the id of the current document but never any parent. What’s wrong?

    Thanks
    Martin
      • 36805
      • 354 Posts
      Quote from: FuryDE at Jun 17, 2007, 02:36 PM

      [...]
      [!Wayfinder? &debug=`1` &startID=`[[UltimateParent]]` &hideSubMenus=`true` &outerClass=`leftmenu` &rowTpl=`wfRowTpl` &selfClass=`self`!]

      [...]
      use &startId instead of &startID
        • 10313
        • 375 Posts
        Thanks, that did it smiley

        Martin
          • 23372
          • 7 Posts
          for me works the ultimatParrent almost perfectly

          I have three menu’s. top --- left --- submenu

          in the submenu i want to set all the submenus of top and left

          That works great, but when i click on a menu-item in the submenu, the submenu dissapear.

          This is what i’ve got
                  <div class="leftmenu">
                            [[Wayfinder? &startId=`3` &level=`1` &hideSubMenus=`true` &outerClass=`nav1`!]]
                  </div>
          	<div id="headernav">
          		[[Wayfinder? &startId=`0` &level=`1` &hideSubMenus=`true` &outerClass=`nav2`!]]
          	</div>
          <div id="headersubnav">
          				[!Wayfinder? &startID=`[[UltimateParent]]` &level=`1` &hideSubMenus=`true` &outerClass=`nav2`!]
          </div>


          Why does the submenu dissapear when I click on a submenu-item?
            • 2954
            • 40 Posts
            I often want to use a parent’s chunk in its children, for instance a header graphic for a section that is applicable to all children. I’d call it with
            {{header-[*alias*]}}

            I wanted to create a single template I could use for all children pages that would work this way based on UltimateParent.

            The code below uses the UltimateParent’s alias to insert the chunk that would apply, assembling the call for the chunk in the snippet.

            Below is an updated version of UltimateParent 2.0 that will insert a chunk call. I’m sure this can be improved, but it’s a start for "UltimateAlias"

            <?php
            /**
             * @name UltimateParent
             * @version 2.0 beta (requires MODx 0.9.5+)
             * @author Jason Coward <[email protected]>
             * 
             * @param &id The id of the document whose parent you want to find.
             * @param &top The top node for the search.
             * @param &topLevel The top level node for the search (root = level 1)
             * @param &alias Boolean for returning the alias of a page instead of its number.
             * @param &chunk The name of the chunk combining with the alias
             * 
             * @license Public Domain, use as you like.
             * 
             * @example [[UltimateParent? &id=`45` &top=`6`]] 
             * Will find the ultimate parent of document 45 if it is a child of document 6;
             * otherwise it will return 45.
             * 
             * @example [[UltimateParent? &topLevel=`2`]]
             * Will find the ultimate parent of the current document at a depth of 2 levels
             * in the document hierarchy, with the root level being level 1.
             *
             * @example [[UltimateParent? &alias=`1` &chunk='sidebar-']]
             * Will find the alias of the parent page, for example 'products' 
             * and then insert it into a chunk command:
             * {{sidebar-products}}.
             * This allows you to specify a single chunk to be used in all children pages.
             * 
             * This snippet travels up the document tree from a specified document and
             * returns the "ultimate" parent.  Version 2.0 was rewritten to use the new
             * getParentIds function features available only in MODx 0.9.5 or later.
             * 
             * Based on the original UltimateParent 1.x snippet by Susan Ottwell
             * <[email protected]>.  The topLevel parameter was introduced by staed and
             * adopted here.
             */
            $top= isset ($top) && intval($top) ? $top : 0;
            $alias= isset ($alias) && intval($alias) ? $alias : 0;
            $chunk= isset ($alias) && isset ($chunk) ? $chunk : "";
            $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;
                        }
                    }
                }
            }
            if ($alias != 0) {
            	$parent = $modx->getPageInfo($id,1,"alias");
            	$alias = $parent['alias'];
            	return '{{'$chunk.$alias.'}}';
            } else {
            	return $id;
            }
            ?>
              • 33372
              • 1,611 Posts
              Or you could do it the other way around with something like [!GetField? &id=`[[UltimateParent]]`!].
                "Things are not what they appear to be; nor are they otherwise." - Buddha

                "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                • 37210
                • 131 Posts
                Here’s my snippet if anybody is interested. I used GetField before but it’s been phased out from Revo, so here’s my updated solution.

                [[UltimateParent? top=`[[++site_start]]`]]


                I use it in a Wayfinder snippet which you can see below. I use it for a side menu which will always start from the ID of the uppermost container RIGHT BELOW the home page. So the side menu will change depending on what section (container) you’re in. But once you’re in that section, the side menu will stay consistent.

                [[!Wayfinder? &startId=`[[UltimateParent? top=`[[++site_start]]`]]`]]



                I’ve just started using Revolution and I’ve been hunting here and there for replacements of old snippets I used to use (GetField --> GetResourceField, DocManager --> Batcher, AjaxSearch --> SimpleSearch, Ditto --> GetResources). So far, it has been really easy to find information about the upgrade. It’s obvious that the MODx team has made sure to organize plenty of documentation to help us out. Thanks heaps.
                  • 20093
                  • 81 Posts
                  I had to add a '.' before $chunk in line 60 to get this version to work:

                  return '{{'.$chunk.$alias.'}}';