use the api-function $modx->parseChunk
http://wiki.modxcms.com/index.php/API:parseChunk in your loop and collect your output into an output-var like so:
<?php
//your code.............
foreach($rows as $row){
$output.= $modx->parseChunk($tpl, $row, '[+', '+]');
}
return $output;
Ah ok, seems to work, thanks for that! But what if I want to output it to a set of pre-named placeholders?
The problem is that you’ll be overwriting those placeholder values each time through the loop, so you’ll only get the values they have on the last iteration. That’s why you need to either use parseChunk(), getChunk() or use str_replace() each time through the loop to add the results to the $output variable.