-
- 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?
-
- 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.
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.
-
- 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.