-
☆ A M B ☆
- 24,524 Posts
No, a snippet loaded via getChunk or parseChunk is not processed through the parser, so snippets, TVs and other MODx tags won’t be evaluated.
parseChunk lets you use placeholders set by the calling snippet; it merges the placeholders in the chunk with their values. So you would need to have the snippet code that’s in the chunk snippet now in your calling snippet, and set placeholders.
-
☆ A M B ☆
- 24,524 Posts
That’s not because the snippet was processed by the getChunk function, it’s because the document went through the main parser again after the chunk content containing snippet tags was inserted. There may be circumstances where it’s reached the max number of passes through the parser, although it probably usually will go through again. Just don’t be too surprised someday if such a getChunk function call doesn’t produce the expected results.
i’m new in modx and i have some wuestions about snipets and parsing chunks .. I wanted to do somethig but without success so i need a litle help ..
I want to call a snippet in a template, and that snippet will display a chunk in a loopt ... so i want that the snippet do a loop of chunks, and fill it each loop with different data .. i want to create some kind of list ...
in this example i wanted to send count $i data to the chunk
i tryed in this way but didn’t worked:
TEMPLATE:
[[test_snippet]]
SNIPPET test_snippet
for ($i = 1; $i <= 5; $i++) {
$modx->setPlaceholder(’xxx’,$i);
echo ’{{test}}’;
}
CHUNK {{test}}
<div> [+xxx+] </div>
RESULT: i get chunk displayed 5 times with value 5 .. i didnt get each loop right no. but i got the last one ..
-----------------
Then i tryed:
SNIPPET test_snippet
for ($i = 1; $i <= 5; $i++) {
$x = ’{{test}}’;
$x = str_replace(’[+xxx+]’,$i,$x);
echo $x;
}
no success ...so i tryed
SNIPPET test_snippet
for ($i = 1; $i <= 5; $i++) {
$chunkArr = array(’xxx’=>’aaa’);
$test = $modx->parseChunk(’test’, $chunkArr, ’[+’, ’+]’);
echo $test;
}
..still no success ..
How i can do this ? .. a snippet wich gather data and for displaying it use a chunk ?
Build the output in your snippet:
<?php
$output = '';
for ($i = 1; $i <= 5; $i++) {
$temp= $modx->getChunk('test');
$temp = $str_replace('[+xxx+]',$i,$temp);
$output .= $temp;
}
return $output;