We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32230
    • 18 Posts
    That’s Grrrrrreat Susan.

    I see .... so your template files contain the snippets and the ’bit of code’ that calls them... so I should just be able to add your snippets and code, tweaking the css as required and the id numbers of pages/folders ??

    I’ll give that a go now ......
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Exactly. Just look at the template file and see how I called the snippets. You can even check the .css file to see how I styled the lists. I have the .css file divided with comments so you can find the right place easily.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 32230
        • 18 Posts
        Hmmm... for some reason, not all my sub menus are coming through ? and when I click a sub menu link (and go into that folder) the subs disappear altogether ... ??

        Maybe setting up a fresh template will help ...
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          No, I see what you mean. When you click on a submenu item, you go to its page, and the snippet looks at its id to make a menu from, and you want the menu based on its parent’s id. I do have another snippet that would work, it goes up the Tree from the current document and returns the ID of the ultimate parent (the one whose parent is 0). This would only work if your main menu has its root at 0, though.

          You would use this for the side menu:
          [!DropMenu?startDoc=[[getUltimateParent]]!]


          I wrote it a while ago; I need to rewrite it to use the new MODx db API.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 32230
            • 18 Posts
            Quote from: sottwell at Nov 03, 2005, 06:03 AM

            No, I see what you mean. When you click on a submenu item, you go to its page, and the snippet looks at its id to make a menu from, and you want the menu based on its parent’s id. I do have another snippet that would work, it goes up the Tree from the current document and returns the ID of the ultimate parent (the one whose parent is 0). This would only work if your main menu has its root at 0, though.

            You would use this for the side menu:
            [!DropMenu?startDoc=[[getUltimateParent]]!]


            I wrote it a while ago; I need to rewrite it to use the new MODx db API.

            Am I right in thinking then that I need to either create a series of TVs then, applied to each page that uses this different snippet depending on whether you’re going up or down levels ??
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              You could use a TV, and edit it with each document with the ID you want to use for the root of that document’s menu, and use the TV in the snippet call:

              [[DropMenu?startDoc=`[*SubID*]`]]
              


              However, this would mean you would have to edit this TV for every page. (a TV can be modified on a page-by-page basis, a very useful feature). Actually, the TV could be written to produce a drop-down list based on root-level document IDs, and then you would just select the the one you want, but still, you’d have to do it with each and every document.

              There are two other methods, however.

              I have a snippet that returns the "ultimate parent" (I just updated it). However, the way the DropMenu snippet is written, there is no way to tell it to not do a menu at all. I could hack it with a one-liner that would cause it to simply abort if it’s passed a value of -1 for the startDoc, and my ultimate parent snippet would return -1 if the document’s parent is 0, meaning it’s a root-level document.

              Or, we could go with the standard DropMenu and the "ultimate parent" snippet, and make another snippet that will replace your side menu’s opening container <div>, if the document’s parent is 0 it will generate a <div class="hide">, and you can simply hide it in the CSS, while it the document’s parent is not 0 it will generate a <div id=#sideMenu>.

              Option 2 is the simplest. Option 3 is good for compatibility; it will work with any menu snippet.

                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                I need to go take a walk and blow the cobwebs off. The "ultimate parent" snippet works great just as it is; if the document’s parent is 0 then its ID is used. Otherwise, it goes into the loop of working up the Tree.

                Here it is; it’s extremely simple:

                $id = $modx->documentIdentifier;
                
                $pid = $modx->getParent($id,1,"id");
                
                if($pid['id'] == 0) { return $id; }
                
                while ($pid['id'] != 0) {
                    $id = $pid['id'];
                    $pid = $modx->getParent($id,1,"id");
                }
                return $id;
                


                Use it like this:

                [!DropMenu?startDoc=`[[UltimateParent]]`!]


                adding any other arguments you want to send to DropMenu as usual.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 32230
                  • 18 Posts
                  Quote from: sottwell at Nov 03, 2005, 07:29 AM

                  Here it is; it’s extremely simple:

                  I’m sorry Susan, we’re still talking different languages .... I’m completely lost now shocked
                  Thanks for all your help - but I’m struggling to get to grips with this ... just a learning curve thing on my part .....

                  Ok - do i create a new snippet - "ultimateparent" using the code, and then add the [!DropMenu?startDoc=`[[UltimateParent]]`!] code to my template ?
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Yes, create a new snippet and copy/paste this code into it. Name it whatever you like; but just make sure to use the same name when you use it! It is case-sensitive, so UltimateParent has to be called just like that.

                    Make sure that you use the [!...!] form to surround the whole DropMenu snippet, other wise the parser will get confused and won’t handle the [[UltimateParent]] snippet properly.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 32230
                      • 18 Posts
                      Still ain’t working for me I’m sorry to report ....