After much consideration, I decided to go with XML based templating for the next version of Ditto over the double placeholder technique that kylej helped me out with (REGEX HELP topic). The reason is very simple: you can collapse xml tags in any RTE but you can’t collapse [++tag++] and [++/tag++] in any.
So, I whipped up a quick parser based on REGEX which works great. Except when it needs to handle recursive templates like the archive. It just plain fails. I need a function that can turn this:
<ditto:archive>
<h3>Archives</h3>
<div id="ditto_archivelist">
<ul id="ditto_ul">
<ditto:year>
<li><span class="ditto_year">[+year+]</span>
<ditto:month>
<li><span class="ditto_month">[+month+]</span>
<ul>
<ditto:item>
<li><a href="[~[+id+]~]">[+title+]</a> (<span class="ditto_date">[+date+]</span>)</li>
</ditto:item>
</ul>
</li>
</ditto:month>
</li>
</ditto:year>
</ul>
</div>
</ditto:archive>
Into an associative array containing the content of each template and only that template (not its children). Places where a subtemplate exists should be replaced with a ditto prefixed placeholder.
The array for year should look like this:
$array[’year’] = ’<li><span class="ditto_year">[+year+]</span>[+ditto:year+]</li>’;
I have tried for several days to find an efficient method of doing this but have come up empty. Any help would be greatly appreciated.