Well, I've tried a couple of template engines. I used
HTML_Template_IT for a while but it's a replacing system rather than a real template engine and I didn't like this. Then I started to work with
Smarty. Then I lost $1500 because I didn't RTFM Smarty docs and I couldn't finish the project in time. Lesson learned.
Well, this sounds a bit lol, but I didn't wanted to learn another language. You cannot just figure out things. You have to
learn Smarty. I couldn't use associative arrays (you have to assign the key for a variable first and you can use that variable to index the array - but you can't use a string index directly). Smarty is too complex
for me. The other thing I didn't like is that it's a compiling engine and it has multiple directories which should be placed outside htdocs.
Then I met the
Savant stuff written by Paul. He proposed it as a PEAR package but the community didn't accept it because there are already 5 template engines in PEAR and (besides I think Savant is a great thing) I feel o.k. that it didn't get accepted into PEAR because of the same reasons that the community said. Then Alan came up with
Flexy and showed that it's pretty easy to make wrapper classes for Flexy so that it can act like it was another template engine - Savant for example. He had a
blog entry that said Smarty is not the best template engine around there and I hoped Alan had the same in his mind when writing Flexy as me. Then I took a closer look at Flexy and there were three things I really liked. The first one is that you can use special HTML properties in your HTML tags and flexy can parse that out. You can repeat a table row like this:
<tr flexy:foreach="a,k,v">
<td>k is {k}, and v is {v}</td>
</tr>
This is great. I've never seen any other template engines capable of this. The another great thing is that it can parse your forms so you can assign field values directly from within your PHP scripts. The third thing was a small one: by default, it calls htmlspecialchars() on each output, unless you specify to not to do so.
Then I started to work with Flexy, and damn, again, I couldn't use associative arrays... I wanted to use Flexy together with my favourite PEAR package,
DB_DataObject and I couldn't figure out how to do things the right way. I wanted to call PHP functions from my templates but I couldn't.
Conclusion: whatever template engine I've tried (it probably helped me a lot in developing applications faster BUT) all the time, I mean
every time there were things that I couldn't do with them.
(
Update: "limitations" is a good word here.)
So I switched back to Savant. Simple. Nothing to learn. Nothing that you can't do. Pure PHP. I recommend it for y'all. Give it a try. (it has drawbacks also.. if you want your users to be able to edit the templates, it's probably not a good idea to let them enter arbitrary php function calls.. there may be other things.. feel free to comment).