I have a fairly complex page which renders several divs. Each div contains a header, repeating detail information and a footer.
I use a snippet to collect all relevant information from the database. Then in a loop, the snippet produces the required output by parsing several chunks:
for ($i=0; $i<$divCounter; $i++) [
$output = $mdodx->parsechunk('headerChunk', ....);
for ($j=0; $j<$detailInDivCounter; $j++) {
$output = $output . $mdodx->parsechunk('detailChunk', ....);
}
$output = $output . $mdodx->parsechunk('footerChunk', ....);
}
The above works, but there’s a lot of parsing going on and I was wondering whether there’s a smarter approach...
MODx Revolution / MAMP / OS X
One faster method might be to store all the chunks as an array inside the snippet (or in an include file) and use str_replace() to do the parsing yourself. It would make editing the chunks less convenient, and if the page load time is acceptable, it might not be worth the trouble. .