Thanks guys, I tested both of Fuzzical Logic's snippets and the snippet BobRay suggested. And guess what...non of them is working...
I have to admit that I'm totally lost now. BobRay's example is different from the ones we where testing the whole time because here the toArray() is definitely called out of line whereas Fuzzical Logic's and my (not working) examples are all called inline (in the if condition).
I also tested this example, which is very similar to the version of BobRay..
if ( condition ) {
$finalTpl = 'templateChunkA';
} else {
$finalTpl = 'templateChunkB';
}
return $modx->getChunk($finalTpl,$modx->resource->toArray());
Here the toArray() comes obviously
after and outside of the if condition and it is still not working. (now it's getting really confusing or am I missing something here?)
This maybe means we have to change the assumption from the first page to:
When toArray() is called within
or after an if condition it won't refresh uncached content fields from chunks that are nested within the actual chunk if they have already been cached once.
This means the only snippet that is working as expected right now is the following:
<?php
$templateChunkA = $modx->getChunk('templateChunkA',$modx->resource->toArray());
$templateChunkB = $modx->getChunk('templateChunkB',$modx->resource->toArray());
if ( condition ) {
return $templateChunkA;
} else {
return $templateChunkB;
}
[ed. note: paul_kemp last edited this post 14 years, 1 month ago.]