Quote from: stratboy at Oct 26, 2010, 11:56 AM
Pardon, I didn’t understand that. I was sure I could only have output from the final return and never ever could use echo print_r etc..
First, are you working in MODx 1.0 (Evolution) or MODx 2.0 (Revolution)?
Regardless, the echo’d content will be prepended to the output if execution of the Snippet completes successfully, i.e. you could collect output in an array...
<?php
$output = array();
foreach ($collection as $itemkey => $item) {
$output[] = print_r($item, true);
}
return implode("\n", $output);
?>
Or if using Revolution, you can use the log() function:
<?php
$oldTarget = $modx->setLogTarget('HTML');
$output = '';
// opening code to get a collection of objects here...
$collection = $modx->getCollection('modUser', array('active' = true));
foreach ($collection as $key => $object) {
// normal code to set output here...
$data = $object->toArray();
$output = $modx->getChunk('myUserTpl', $data);
// now output some debugging info to the page
$modx->log(modX::LOG_LEVEL_ERROR, "object {$key} = " . print_r($data, true));
}
// do more stuff here
$modx->setLogTarget($oldTarget);
return $output;
?>