What would be best is for you to use the chunk ability in modx. This snippet (let’s call it "GetChildren") does the same as yours:
$id = $modx->getOption('id',$scriptProperties,$modx->resource->get('id'));
$tpl = $modx->getOption('tpl',$scriptProperties,'');
$wrapperTpl = $modx->getOption('wrapperTpl',$scriptProperties,'');
$sortBy = $modx->getOption('sortBy',$scriptProperties,'menuindex');
$sortDir = $modx->getOption('sortDir',$scriptProperties,'ASC');
$c = $modx->newQuery('modResource');
$c->where(array(
'parent' => $id,
'published' => true,
'deleted' => false,
'isfolder' => false,
));
$c->sortby($sortBy,$sortDir);
$resources = $modx->getCollection('modResource',$c);
$output = '';
foreach ($resources as $resource) {
$resourceArray = $resource->toArray();
$output .= !empty($tpl) ? $modx->getChunk($tpl,$resourceArray) : print_r($resourceArray,true);
}
if (empty($wrapperTpl)) return $output;
return $modx->getChunk($wrapperTpl,array(
'resources' => $output,
));
Then create a Chunk you called "gcWrapperTpl" that contains the wrapper:
Then create a Chunk called "gcTpl" that is for each resource result:
<li>
<a href="[[~[[+id]]]]">[[+pagetitle]]</a>
<p>[[+introtext]]</p>
</li>
And finally, call it here:
[[!GetChildren? &id=`IDGOESHERE` &tpl=`gcTpl` &wrapperTpl=`gcWrapperTpl`]]
Obviously you could extend and improve the snippet to use more options....but then you could always use
getResources, which does pretty much the same thing:
<ul>
[[!getResources? &tpl=`gcTpl` &hideContainers=`1` &depth=`1` &parents=`IDGOESHERE` &sortby=`menuindex`]]
</ul>