Quote from: Mark at Aug 19, 2006, 01:58 PM
Jason,
Look at the example. As a user, you have to understand pre and post chunks (8 of them!) versus having one chunk with subtemplates (not a multipart template) for each item that repeats. Yes it is easier to edit multiple chunks for some things but not for subtemplating IMHO.
I’m still not hearing the benefits, nor buying that it’s harder to understand semantically well named, individual subtemplates, or pre or post templates, or whatever kind of templates. They are still combining logic and presentation, and IMHO, that is not the path of evolution I want to see occur within MODx components. A template is a template is a template, regardless of how many other templates it is embedded in or combined with to produce final output, and as we progress towards a more robust and concise model for 1.0, getting rid of code that uses proprietary methods of templating in key components that are distributed with the framework would be the first step towards making those components reflect the best practice approaches we want to exemplify.
All that should be involved in subtemplates is a loop in your snippet logic with a set of replacement variables for each iteration, being replaced in that subtemplate. And this code should be relatively trivial, especially once we have recursive parsing performed by the snippet elements themselves (definitely 1.0, possibly 0.9.5 recursive parser, though I’m not as sure about the latter; Raymond?); i.e. once a snippet returns it’s content, that content is then scanned for additional MODx tags, and executes until they are all replaced or a specified maximum number of iterations is met.
To exemplify this, here is an example of what I mean, where subtemplates are driven by separate snippet calls, providing loose relationships between the elements and complete isolation of logic and presentation at all levels:
<?php
// MySnippet snippet
$content= $modx->getChunk('MySnippet.ContainerTpl');
$data= some_code_or_function_to_perform_snippet_logic_and_get_data_to_iterate_over();
$modx->setPlaceholder('MyDataToIterateOver', $data);
return $content;
?>
<!-- MySnippet.ContainerTpl -->
<div>
[[MySnippet.Iterator? &data=`MyDataToIterateOver`]]
</div>
<?php
// MySnippet.Iterator snippet
$output= '';
if ($collection= $modx->getPlaceholder($data)) {
foreach ($collection as $item) {
$output.= $modx->parseChunk('MySnippet.IteratorTpl', $item, '[+', '+]');
}
}
return $output;
?>
Consider if someone wanted to just change the way the iterator portion worked, they don’t need to touch say the Ditto snippet at all, just modify the DittoIterator (or duplicate, rename it, and modify the chunk/template that calls it) to do what they want, without getting lost in a sea of code in a single snippet or a specific piece of template markup buried in a set of proprietary tags or content splitters.
I’m not saying I can’t be convinced otherwise, but so far, I’ve still seen no actual benefits to combining templates and subtemplates. In fact, the tendency towards this templating appears to me to just be a side effect of the way the components have been approached thus far in conjunction with some limitations of the current core.