DOMtempl

HTML templating that brings you peace

Blog - Manifesto

Why

Because going into templates/default/articles/post/pages.php to find 2 lines of templating / HTML soup is maddening.

Because needing a full back-end to see one CSS change is angering.

Because having a template that is not HTML and thus robs you of your favourite developer tools is suffering.

And so

By misunderstanding ideas of XSLT, abusing HTML5 custom attributes, and leveraging the all-powerfull DOM, comes templating library that brings you the peace of mind.

It is a work in progress, so if you find something that is maddening, angering or leads to suffering, please make sure to have a say.

GitHub repo

git clone https://github.com/makesite/domtempl.git

Take a look at the joyfull samples page and a boring documentation section.

Why not

DOM parsing is rather fast (and should only get faster), but can be memory-expensive at the same time.

Breaking the template down to multiple files is considered evil inside temple walls, and shall not be discussed here. You can probably achieve what you desire by assigning the output of FRAGMENT parsing onto another template, but you're on your own here.

Third problem is best described like this:

<div>
    <?= $a ?>
    <span><?= $b ?></span>
    <?= $c ?>
</div> 

Is a pretty common construct, which is not possible in DOMtempl. Several workarounds are possible, i.e wrapping \$a and \$c into their own html elements, or generating html by hand and setting it to div element; both are not ideal. It could be argued, however, that stand-alone text elements should not exist from semantic point of view at all.

Lastly, you can't have advanced scripting in your templates. That is by design, but could become problematic in some cases.

License

Two-clause BSD.

P.S.

While pondering a python port, it came to my attention, that DOM-based templating is prevalent there, unlike the world of PHP. Several interesting projects exist, so you should probably use one of them.