Hi,
I want to add a block only if there are published childs.
I know PHx but I don't know how to test the number of active childs.
I didn't find any extra for Evolution....
-
☆ A M B ☆
- 24,524 Posts
You can use a snippet using the getActiveChildren() API function, and count the results. However, since this API function will run a relatively complex query to return all the information on the active children of the given resource including permissions, it might be lighter on your site to use a simple query using the SQL count() function with an appropriate WHERE clause.
$num = $modx->db->getValue($modx->db->select('COUNT(*)', $modx->getFullTableName('site_content'), 'parent=2 AND published=1 AND deleted=0'));
if($num > 0) {
$output = 'whatever you want to display';
return $output;
}
return;