We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36786 ☆ A M B ☆
    • 209 Posts
    I had been given some PHP for a snippet on the forums a while back to assist me in submenus on the sidebar of pages with children resources. However, it no longer works in Revo 2.3. Can someone assist me in modifying it so it is 2.3 compatible?

    Snippet:
    <?php
    $document = $modx->getObject('modResource', $id);
     
    if($document){
        return $document->hasChildren()? '1' : '0';
    }
     
    return '';


    Use:
    [[hasChildren:is=`1`:then=`getResources Call`]]

    This question has been answered by sottwell. See the first response.

      Ben Morrison
      Hacking templates to pieces since 2003
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      It looks like it expects a property of &id with the ID of the parent.
        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
      • discuss.answer
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        If you want the snippet to use the current resource's ID by default try this version
        <?php
        $id = $modx->getOption('id', $scriptProperties, $modx->resource->get('id'));
        $document = $modx->getObject('modResource', $id);  
        if($document){
            return $document->hasChildren()? '1' : '0';
        }
        return '';


        That extra line says "get the option named 'id' - from the snippet's properties - by default use the current resource ID".

          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
          • 36786 ☆ A M B ☆
          • 209 Posts
          Thanks guys!
            Ben Morrison
            Hacking templates to pieces since 2003