Templating engines, who’d have ’em?

So what do you see as the purpose of a templating engine?

I’d say it’s a method of separating paradigms and abstracting the backend. Some engines enforce this by implementing their own minimal set of directives, others seem to follow the idea of restricting use, yet implement a vast amount of directives. Take Cheetah for example. Others just allow you to drop code in wherever and however you like.

It would be far less complicated to simply allow inline code, but then there is the argument that if developers are allowed to mix up the paradigms, they probably will.

So when it comes to writing your own engine, do you simply allow inline code, implement just a handful of directives or implement a huge set? If you implement just a handful, people may say “well look at engine XYZ, it has 3 times more features”, if you go for straight inline code, people will say it’s insecure and mixes up the paradigms. Yet I look at Cheetah’s list of directives and can’t help but think it’d so much simpler to just allow inline code. Note that Cheetah as more than enough directives to royally screw up the paradigm.

So at this point I’m thinking I’d rather get rid of the templating engine all together. One solution could be XSLT. XSLT has all the conditional and looping goodness you’d ever have needed from a templating engine. With a simple script to convert Python data structures into XML and XPath to access them, you’re all set. XSLT is a damn sight more complex than your average templating engine syntax though, and this would deter many developers who’d never used it before.

So what’s the solution to all of this? I don’t know, though there are 2 methods I prefer.

The first method is just simply allow inline python code, and then try to encourage developers not to mix up the paradigms and restrain themselves to using only the most basic of code in the templates.

Method #2 is to use a series of regular expressions to restrict usage.

However, I don’t believe in restricting what developers can do. There are after all plenty of other places the developer could screw up the paradigms.

I was hoping this post would help me make my mind up and pick a solution, though really I’m non the wiser.
It’d be great to hear peoples thoughts on this.