We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28173
    • 409 Posts
    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....
      • 28042 ☆ 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;
      

        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org