Hi, I am writing a snippet that takes an array of pages (rather than just a specific directory) and outputs them onto a single page. The issue is in the display of this data. When I have the HTML code embedded in the snippet, the data works perfectly. However, when I try to abstract the content layer out by using a chunk as the template, what ends up happening is that I get the same data displayed for as many times as there are items in the page array.
Snippet Call on my page:
[[ShowSetOfPages? &page_array=`34,5,6,7,8` ]]
Snippet "ShowSetOfPages":
$pages = isset($page_array)? $page_array : '';
$template = isset($tpl) ? $tpl : 'SetOfPagesChunk';
if ($pages)
{
$pages = explode(',',$pages);
foreach ($pages as $root)
{
$doc = $modx->getDocument($root);
$displayTitle = $doc['longtitle'];
$content = $doc['content'];
$modx->setPlaceholder('link', $activeRoot);
$modx->setPlaceholder('displayTitle', $displayTitle);
$modx->setPlaceholder('content', $content);
$finalString .= $modx->getChunk($template);
}
}
return $finalString;
The last page (#8) gets repeated 5 times on the webpage rather than each page being displayed as expected. Here’s the example URL -
http://scoba.us/test.html It’s as if the getChunk doesn’t get executed until the very end of the function. Is there any way to execute the getChunk function in a for loop or is there a workaround to get the same behavior?
Thanks.