So I’ve got a site where I’m trying to modify the output of Ditto based on whether a Parent document has children or not. In the tree I’ve got the following setup:
Directory Pages
- Category Name 1
-- Business Name 1
-- Business Name 2
-- etc.
- Category Name 2
-- Business Name 1
-- Business Name 2
-- etc.
...
etc.
So on the "Directory Pages" document, I had Ditto outputting the Category Name with it’s children underneath the Business Name. But my challenge is figuring out how to not have the Category Name not be output if that specific Category has no children. Obviously I could simply unpublish it, but I need all the Category Names set to publish b/c we’re using the Category Names elsewhere in the site. So my set up is like so:
[[Ditto? &parents=`8` &tpl=`directory_tpl` &sortBy=`menuindex` &sortDir=`ASC`]]
Then the directory tpl has:
[+pagetitle+]
[[Ditto? &tpl=`directory_organization_link_tpl` &parents=`[+id+]` &sortBy=`menuindex` &sortDir=`ASC` &noResults=`Coming Soon`]]
The pagetitle above is the Category name and the Ditto call underneath it is the children being outputted.
I tried to create a snippet to output nothing (no category name or children) in the "directory_tpl", but I’m not sure where I went wrong or if there is a better way to do this. Here’s the snippet I created:
<?php
// initialize and get the number of children for a particular parent
$childCount = 0;
$children = $modx-> getDocumentChildren($parent);
// determines whether childCount and children are greater than 0
if ($childCount < count($children))
// If childCount is greater to the value of 0, then return the following chunk which has the Category and children here
echo "{{child_count_gt_0}}";
// But if there are no children for the parent document, return the following below which is empty
else
echo "{{child_count_eq_0}}";
?>
Anyone got any ideas? Thanks!