Quote from: Bruno17 at Dec 08, 2008, 03:02 PM
So, if I understand, every snippet which handles with templates and/or chunks like Ditto, wayfinder, maxigallery and so on needs its own template-processor-class?
Not at all. The problem is they now do all sorts of things internally to deal with input themselves (i.e. @CODE was made up by one of those snippets I believe, and has never been part of the core); they just need to accept the content as input, since that is now possible. You can pass content directly in tag strings now, so how it is retrieved is irrelevant. In addition, you can nest tags infinitely, so there is no limit to how you decide to get content in and out of your various elements.
Quote from: Bruno17 at Dec 08, 2008, 03:02 PM
I was hoping there is an easy way in revolution where you can send your placeholders and your template/chunk name or code to a given function and it would return the processed and PHx-filtered output-string as in my little experiment
There is, for chunks:
$modx->getChunk('parsetest', $daten);
[[!$parsetest? &ph1=`value1` &ph2=`value2` &ph3=`value3`]]
To parse your own content, you could create a transient modChunk instance at runtime and pass properties and content directly to the process() function:
$content = file_get_contents(MODX_BASE_PATH . 'path/to/file/content.tpl');
$chunk= $modx->newObject('modChunk');
$output = $chunk->process($properties, $content);
return $output;
Snippetize that and you can easily use that anywhere, via API or tag.
Or you can even use the parser directly, with full control over what it does with properties, non-cacheable and/or unprocessed tags, etc.:
<?php
$content = isset($content) ? $content : '[[+ph1]]<br/>[[+ph2]]<br/>[[+ph3]]<br/>';
/* turn the script properties into placeholders and keep overwritten values for restoration */
$restore = array();
$placeholders = $scriptProperties;
if (is_array($placeholders) && !empty($placeholders)) {
$restoreKeys = array_keys($placeholders);
foreach ($restoreKeys as $phKey) {
if (isset($modx->placeholders[$phKey])) $restore[$phKey]= $modx->getPlaceholder($phKey);
}
$modx->toPlaceholders($placeholders);
}
/* collect element tags in the output and process them */
$maxIterations= isset ($modx->config['parser_max_iterations']) ? intval($modx->config['parser_max_iterations']) : 10;
$modx->parser->processElementTags('', $content, false, false, '[[', ']]', array(), $maxIterations);
/* remove the placeholders set from the properties of this script and restore global values */
$modx->unsetPlaceholders(array_keys($scriptProperties));
if ($restore) $modx->toPlaceholders($restore);
return $content;
?>
With a little imagination, you can create all kinds of general purpose snippets to manage parsing content from anywhere, including outside of core MODx elements (i.e. chunks, TV’s, etc.).
And soon, Revolution will support file-based content for all chunks directly, so if you want the content managed in an external file, you will be able to use it without doing anything special; it’ll just be an element that references it’s source content from the file-system. But this feature will likely be in a release after the initial one.