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

    I looked around and couldn’t find a single example of how to make a menu with getResources, or simply with MODx 2 in general (I know I could still use Wayfinder or Ditto, as I did before, but as I understand, they’re not the recommended way to do it anymore).

    I just want to make a relatively simple menu, and I got it to work, but I need a few more things that I can’t figure out.

    Here’s my code:

    <ul id="menu">
    [[!getResources? &parents=`0` &depth=`0` &sortby=`menuindex` &sortdir=`asc` &tpl=`MenuItem`]]
    </ul>


    And In the MenuItem chunk:

    <li><a href="[[~[[+id]]]]">[[+pagetitle]]</a></li>


    Now, here’s what I’m missing:


    • Giving a particular class to the current page
    • Showing the child pages of the current page (and only of the current page)

    Is it possible with getResources, and if so how?
    Thanks in advance.
    • Hello,

      Wayfinder is still the recommended method to create menus, where did you see otherwise?
        Patrick | Server Wrangler
        About Me: Website | TweetsMODX Hosting
        • 3749
        • 24,544 Posts
        Ditto is deprecated in favor of getResources, but Wayfinder is not. It’s possible to do a menu with getResources, but I’ve yet to see a menu that Wayfinder won’t produce.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 5340
          • 1,624 Posts
          Quote from: AMDbuilder at Nov 17, 2010, 01:57 AM

          Hello,

          Wayfinder is still the recommended method to create menus, where did you see otherwise?

          Hi BobRay/AMDbuilder,

          Last time I checked it doesn’t work with contexts. Any news on a new version?

          Thanks
          • Wayfinder works fine with contexts, or are you trying to generate a menu across two or more contexts? If so could you elaborate on what you are trying to accomplish?
              Patrick | Server Wrangler
              About Me: Website | TweetsMODX Hosting
              • 28589
              • 56 Posts
              Quote from: AMDbuilder at Nov 17, 2010, 01:57 AM

              Wayfinder is still the recommended method to create menus, where did you see otherwise?
              Oh okay, I must have misread then.
              I take it that means what I want is not possible with getResources.

              I guess I’ll go for Wayfinder then.
              Thanks!
              • Hi,

                @Stifu : it’s possible to do menus with getResources, you just won’t have all the Wayfinder possibilities out of the box. For your actual question, you might want to have a look at &pageActiveTpl param, which might solve your problem (but as said, WF is still recommended).

                @AMDbuilder : i’m having troubles with WF in contexts too. I’m basicaly trying to generate the menu from startID=0 in a context other than web, and nothing outputs. I were told the workaround would be to but the whole structure in a container resource and use &startId=`containerID` but that’s a workaround…

                @BobRay : Wayfinder is nice, but getResources introduced some nice features too i didnt see in WF, for example &idx with which you can produce nice & sorted dropdown menus you can’t with WF (at least without php coding)
                  • 31037
                  • 358 Posts
                  Another way of adding class="active" is to just add an if statement with If snippet, or I guess, even an output modifier.

                  With If snippet in the template:

                  <li><a [[If? &subject=`[[+id]]` &operand=`[[*id]]` &then=`class="active" `]]href="[[~[[+id]]]]" title="[[+pagetitle]]">[[+pagetitle]]</a></li> ​

                  Could also be used to make another getResources call I guess... not tested that though, by adding a similar If call with

                  &then=`<UL>[[getResources? &tpl=`anotherTplWithPerhapsYetAnotherGetRes-callForThirdLevel` &parents=`[[*id]]` ]]`

                  Although I might put the "IFs" in a sepetare chunk...

                  Perhaps not the prettiest way, but as usual with MODx you can do anything, and in a huge number of ways... tongue
                    • 33657
                    • 128 Posts
                    [[+id:is=`[[UltimateParent]]`:then=`class="active"`]]


                    you could do that in your get resources snippet and if you have ultimate parent installed it will check the curent id, if its ultimate parent it will make it active.
                      • 14162
                      • 67 Posts
                      This gives the active page the relevant class:
                      [[+id:is=`[[*id]]`:then=`class="active"`]]


                      And for nested nav you can use:
                      [[+id:is=`[[UltimateParent? &id=`[[!*id]]`]]`:or:is=`[[*id]]`:then=`class="active"`]]


                      Make sure the resource is uncached. [ed. note: jimbob72 last edited this post 12 years, 5 months ago.]