If getResources parent is not empty display chunk

1.9k views Asked by At

I'm a noob in the modx world. I have a page with subpages and I using getResources to display the content of those in tabs on the parent page.

What I would like to do is only display that chunk if the parent has subpages?

So something like this, but this is obviously not right because its not working.

[[!getResources &parent:notempty=`[[$chunk]]`]]  
2

There are 2 answers

0
goldsky On

it's &parents , with "s".

Anyway, If you want to use output filter for snippet, you add it BEFORE the question mark:

[[!getResources:isempty=`No content is available`? &parents =`[[*id]]`]]
0
Sean Kimball On

Give this a shot, create a new snippet for this;

<?php
// get the current resource id
$id =  $modx->resource->get('id');

// get the resource object
$resource = $modx->getObject('modResource', $docId);

// make sure we have a resource
if($resource){

    // see if the resource has children
    $hasChildren = $resource->hasChildren();

    if($hasChildren){ // pretty sure hasChildren returns 1 or 0

        // optionally, retrieve the chunk & populate it.
        // replace your-chunk-name and the placeholders with your values. 
        $output = $modx->getChunk('your-chunk-name',array(

            'placeholder-1-name' => 'value',
            'placeholder-2-name' => 'value',
            'placeholder-3-name' => 'value',
            'placeholder-4-name' => 'value',

        ));

        return $output; 

    }

}

return true;