DOMtempl

HTML templating that brings you peace

Blog - Other templating engines

DOM-based

XTemplate (PHP)

I found this one while working on initial versions of DOMtempl and considered using it. I decided against it, in the end, as my vision was a little bit different.

XTemplate relies on comments, more specifically, commands hidden in the comments. I don't know if they use DOM or string parsing for that, but either way it's rather clever.

Due to this mechanism, it can also parse specific parts of the template by request, and not necessary the whole thing at once.

DOMTemplate (PHP)

This one is a close cousin. Found it way into DOMtempl's life. Was surprised to read the thinking behind it. Way better writing, than anything I could ever come up with to explain the darn thing!

The main difference is that it advocates direct DOM manipulation from the controller. I think that's too excessive.

MELD3 (Python)

This one is elegant! They use namespacing (instead of data-attributes like DOMtempl does) to sprinkle meaning into the templates, and I instantly fell in love with that idea.

Namespaces make much more sense, from all points of view, to use with extra templating attributes.

But PHP's support for DOM *NS functions was bad at the time, so I decided not to pursue it.

Another difference is that they decided not to build up a tree, but a flat table with meld:id. I believe that's underusing the power of DOM, which gives you a tree naturally.

String-based

Mustache

Although I swear by DOM-templating and curse loudly when string-based templating is mentioned, it, of course, has it's uses (text/plain e-mail notifications, anyone?).

Out of all the engines, I naturally prefer those, that do not allow me to inject any code, and maintain the view/controller separation. Mustache, and it's family of derivatives, is a pretty good choice in that regard.

Additionally, it's easy to read, it builds-up paths, and it's tailored to JSON-like data structures.

PHPsoup

Vanilla PHP templating, i.e.:<b><? echo $title; ?></b>. This is a scourge of php, hated by most. When used correctly, can be quite nice and unobtrusive, as proven by many modern PHP frameworks.

Still, the temptation to write direct php into those is too large to overcome and I've yet to see a project that didn't succumb to it at one point or another.

Those are also the fastest (for PHP) and nothing will ever beat them in speed. That is way many engines have an ability to "compile" their templates into phpsoup.

ERB (Ruby)

I didn't understand this one. What purpose would such an obscure syntax serve? Is there a term "rubysoup"? Because that's what it is. Way too much logic.

P.S. No offense to other templating engines intended, just trying to express my reasoning for creating Yet Another One. If you must quote me bad-mouthing someone, tho, here you go: Smarty (PHP) can go fuck itself.