We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36549
    • 572 Posts
    Hi,
    I thought i'd be able to display a sub-nav by using the output filter to ask whether a resource is a container and if it is then display the sub-nav, like this:
    [[*isfolder:eq=`1`:then=`[[$nav-sub]]`]]

    ...but it doesn't work. What am i doing wrong? [ed. note: 9thwave last edited this post 13 years, 5 months ago.]
      www.9thwave.co.uk
         WEB | DESIGN | PRINT
      • 30585
      • 833 Posts
      What do you get when you call [[*isfolder]] on your page?
        A MODx Fanatic
        • 3749
        • 24,544 Posts
        It returns the value (0 or 1) of the isfolder field of the Resource.

        In Revo, isfolder is not set automatically when a resource has children like it was in Evo (though there's plugin I wrote to do that around here somewhere). Your output modifier should work if you manually check the container checkbox on all resources with children.

        As an alternative, you could create a hasChildren output modifier (if there isn't one already)

        Just create a snippet called hasChildren with this code:

        return $modx->resource->hasChildren();



        FYI: hasChildren() and this output modifier actually return the number of children, in case you ever need that. If your output modifier in the tag doesn't work, try changing the snippet code to this:

        return $modx->resource->hasChildren() != 0;
        [ed. note: BobRay last edited this post 13 years, 5 months ago.]
          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
          • 40045
          • 534 Posts
          Maybe the use of getChildIds would be even more efficient for that specific scenario of outputting a subnav:

          // call the snippet childIDs or so
          return $modx->getChildIds($id, 1, array('context' => 'web')));
          
          // not sure if the variable $id is available, if not try $resource->get('id') instead
          


          then something like

          [[getResources? &parents=`-1` &resources=`[[*id:childIDs]]`... ]]


          would return the subnav...totally untested though =)
            • 30585
            • 833 Posts
            Sorry guys, I thought @9thwave wasn't getting any output with the call.
              A MODx Fanatic
              • 36549
              • 572 Posts
              Hi,

              Thanks for all the replies. I'm still not getting the output of my chunk though so i'm perhaps doing something wrong.
              Using BobRays HasChildren like below i get either 1 or 0 rather than the chunk? So at least it's working but how do I display the chunk?:
               [[!HasChildren? &true=`[[$nav-sub]]`]]


                www.9thwave.co.uk
                   WEB | DESIGN | PRINT
                • 30585
                • 833 Posts
                Why don't you do this?

                [[hasChildren:is=`1`:then=`[[$nav-sub]]`]]
                  A MODx Fanatic
                  • 3749
                  • 24,544 Posts
                  You might need this, the output filter is sometimes cranky when there's no else:



                  [[hasChildren:isnot=`0`:then=`[[$nav-sub]]`:else=``]]
                    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
                    • 36549
                    • 572 Posts
                    Got it to work.
                    I had to change the snippet to:
                    return $modx->resource->hasChildren() != 0;

                    Once I changed the snippet i didn't need the :else=``.
                    That's a very handy snippet and will be taking up permanent residence in my standard cloud template.
                    Thanks for everyone's help with this:-)
                      www.9thwave.co.uk
                         WEB | DESIGN | PRINT
                      • 3749
                      • 24,544 Posts
                      I'm glad it worked for you. Thanks for reporting back. smiley
                        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