If you're going to be designating them manually, why not just check the "Hide from Menus" box?
Right, but if you check the "Hide from Menus" checkbox on the empty folders, they won't show in the menu.
If you want to automate things, I think this plugin attached to OnDocFormSave would do it:
<?php
$children = $modx->getMany('Children');
$setting = empty ($children)? true : false;
$resource->set('hidemenu', $setting);
$resource->save();
You could also set isFolder instead, but this would be more straightforward, since it's exactly what you want to do (if I'm understanding you).
I dont think you understand me.
To be more specific... In front end user will create new resource (using formit2resource) and also can choose specific category for resource to be stored in (premade folder). So in menu there could be around 20 folders but only once a new child is added then the folder become visible. Until then, all empty folders are hidden.
Another problem could be the structure. => Folder ->Subfolders->Child
If I understand correctly Subfolder is already Child of Folder, no? But this might be solved by setting the folder resource as a folder or use an empty template.
Quote from: kudykam at Mar 19, 2013, 02:49 AMI dont think you understand me.
It wouldn't be the first time.
I think I get it now. It sounds like you want something like this (with hidemenu checked on all folders).
<?php
if ($resource->get('parent')) { // only act on non-root docs
$parentObj = $resource->getOne('Parent');
/* turn off parent's hidemenu field if set */
if ($parentObj->get('hidemenu')) {
$parentObj->set('hidemenu', 0);
$parentObj->save();
}
}
Note that this will not set hidemenu to true for parents when you delete all their children. To do that you'd need more code and you'd need to attach the plugin to a resource delete event as well.
[ed. note: BobRay last edited this post 13 years, 7 months ago.]
when/how to call this snippet?
It's not a snippet. It would be a plugin attached to the OnDocFormSave event.
Yeah, that what I thought, but it does nothing....
I set directory and its subdirectory to hidden...
Then create resource in subdirectory, but both directories are still hidden...
Sorry, typo in the code. Try the new version above.