We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I can't make [[!HasChildren]] & [[*isfolder]] work with modx 2.3.3, it always display the same result with the checkbox container checked... Is it normal ? Is there an alternative ?

    [[*isfolder:is=`1`:then=`toto`:else=`titi`]]
    [ed. note: hartus last edited this post 8 years, 9 months ago.]
      • 5430
      • 247 Posts
      I assume you mean 2.3? What output do you get without the filters (in other words with just [[*isfolder]]) with the container box checked and unchecked?
        • 3749
        • 24,544 Posts
        I'm not sure this answers your question, but at one time (and in the paper version of my book), those were independent. A resource with children could be set as not a folder and vice versa. I think the latest versions of MODX act like Evo. When a resource gets children, isfolder is always 1. When it has no children, isfolder is always 0. I don't think setting the Container checkbox actually does anything any more.

        There is no hasChildren snippet that I'm aware of, unless you've written one. It would look like this:

        return $modx->resource->hasChildren()? '0' : '1';


        though isfolder would probably be faster and easier, and AFAIK, would give you the same result.
          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
        • I've tried everything, yes i've writen an HasChildren snippet based on yours. But [[*isfolder]] returns nothing & [[!hasChildren]] returns 1.

          But i've a parent ressource (see attachment), i really d'ont get it. It is a fresh install i only have wayfinder & contentblocks as plugins.

          I can provide manager access if needed...

          [ed. note: hartus last edited this post 8 years, 9 months ago.]
          • If the "Container" checkbox is checked, [[*isfolder]] will return 1. If it is unchecked, it will return nothing - the field in the database will be set to 0 - whether the resource still has children or not.

            The circumstances under which 'isfolder' is set automatically are somewhat unclear. Creating a resource under a non-container will make it a container. Dragging and dropping a resource into another resource will not automatically set the 'isfolder' to 1. Likewise dragging a single child out of a container will not clear the 'isfolder' value.

            The hasChildren() API function actually returns the count of resources that have this resource listed as their parent.

            There is also the matter of the cache. A resource's cache file has an array of its settings, so if it's cached with 'isfolder' set to 1 or 0, that's what you'll get.
              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
              • 3749
              • 24,544 Posts
              I'm pretty sure that in older versions of Revo, nothing affected the isfolder field except setting the Container checkbox. Since the effect is now inconsistent, isfolder seems useless.

              Even though hasFolder() returns the count, my snippet called uncached should still accurately return 0 or 1 depending on whether the resource has children. If it's not doing that for you, you might try it without the single quotes to see if it makes a difference.

              return $modx->resource->hasChildren()? 0 : 1;


              Make sure you're calling it in the parent, not the child. If you're calling it in a Tpl chunk, it would have to be rewritten in order to work.
                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