I want to hide all collection resources that have no child-resources in my pdoMenu call. As those are collection resources, their isfolder checkbox is on by default so I can’t easily use something like:
&where=`{"isfolder":"1"}`
Additionally, I need to include all weblink resources, which don’t have children, but should still be shown.
Is there a way to achieve this or is some form of custom snippet necessary?
Maybe it’s easier to use a different approach.
Like deciding inside the template if anything should get output at all, based on the placeholders [[+children]] and [[+class_key]].
Also, you may have to set the property &countChildren to 1 to make it work.
So just adding the &countChildren property completely kills my entire navigation. I’m not sure why this would happen, but it seems this approach is probably not the easiest way.
Does the &where approach not work? I think I would prefer having the unwanted resources filtered before displaying them, so I don’t have to mess with the navigation.
What versions of MODX, pdoTools and PHP are you using.
Maybe you can make it work. But sometimes for complicated filtering(AND and OR conditions mixed) it’s difficult to get the structure right.
But maybe I’m just misunderstanding the question:
So you want to exclude the resources with the “class_key” = CollectionContainer that don’t have children, but you can’t use “isfolder” (because it’s always set to true).
In my opinion it’s easier to query all resources and then filter out the collection containers with something like this in the template: (Fenom syntax)
Another possible solution is to use the &resources property.
Run a snippet that returns the IDs of all the collection containers that have no children. Put a dash before each ID, so they get excluded from the result.
Yes. I have Collection resources that don’t have children (yet). And until they get some I don’t want them to be displayed. There are quite a few, so I don’t want to manually hide them.
You are probably right, but I guess I have to fix the call first, before i can try that.
Also thank you for the snippet suggestion, that might be a good solution, if the others fail.
Just thinking out loud here. For the resources with no children, there will be no resources that have that resource as a parent. I can’t work it out, but I’m pretty sure there’s a single query that will get resources where the class key is something AND the count of resources that have the resource as a parent is >= 1.
I tried adding the mentioned syntax to the parentRow tpl (nav.category.ParentRow), but it removes everything except the very first weblink resource. I feel like something is not working as expected here.
To clarify: when I enable &countChildren it places a big part of my navigation outside of the .container that pdoMenu is called from. So probably something else is interfering?
This sounds like it’s worth a try. Not sure if my knowledge will be sufficient enough for this, though. Will look into it, any more ideas here are definitely appreciated.
Anyway: Here is some snippet code to query the collection containers with no children.
<?php
$sql = <<<SQL
SELECT id FROM modx_site_content SC
WHERE class_key IN ('CollectionContainer','Collections\\\\Model\\\\CollectionContainer')
AND published = 1
AND deleted = 0
AND NOT EXISTS (
SELECT id
FROM modx_site_content
WHERE parent = SC.id
AND published = 1
AND deleted = 0
);
SQL;
$stmt = $modx->prepare($sql);
$stmt->execute();
$ids = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
if (count($ids) > 0) {
return "-" . implode(",-", $ids);
} else {
return "";
}
Thank you for your efforts! I had to adjust the table name according to my custom prefix which left me a bit head scratching at first, but it works great! Thank you again!
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.