I've yet to see a better one in any language - it has things like Unix-like pipe chaining of filters, user defined functions, and intelligent caching built in.
I reduced the number of lines in one codebase I worked on by 70% through use of Smarty.
I've yet to see a better one in any language - it has things like Unix-like pipe chaining of filters, user defined functions, and intelligent caching built in.
I reduced the number of lines in one codebase I worked on by 70% through use of Smarty.
Bolting a template engine on top of that makes no sense whatsoever.
Maybe that seems perverse, but you have stuff like Node.js in existence that oddly enough solves some problems quite nicely, so maybe it works for PHP guys. I'll never see the appeal compared to other languages though.
edit: That being said, the final result looks kind of horrible to me.
But that said: I'm severely puzzled about your choice of HN username.
[1] http://www.ssb.no/navn/sok.cgi?lang=n&fornavn=anders&...
Though I don't like having to use the Smarty psuedo-language, I do like the organization of code that it provides.
Now we've actually moved everything to the client side using Ember and Handlebars templates. JS doesn't have any built-in templating like PHP (which is basically just a template engine), so Handlebars makes it really useful to write up HTML code blocks that get variable insertion and data-binding on the client side.
> include variable insertion (<?=$var?>)
No disable your short tags and any nontrivial template will become ugly as hell, unless you are on php 5.4+ which not many are.But what's really amazing is when you combine Hiccup with Enlive[3]. Enlive can give you a headache when you first start working with it, but then there's an almost magical "aha!" moment, and not long after that you'll never want to look back. By "combine" I mean using Hiccup and metadata from your db (or whatever) to generate empty, logic-less views and then using Enlive to bind in your data.
Combine those steps with your own macros and HOFs, look for some choice places to memoize function calls, and now you're cooking with gas.
[1] https://github.com/weavejester/hiccup
And seriously, check Symfony 2 out.
One of the worst flaws of php is that it makes it easy to mix up code and the view, which is ok if you're writing a single page, and terribly dangerous if you're writing anything more complex.
I've experienced this myself writing templates for things like phpbb (thankfully not something I do frequently) - every time the forum updates, the templates have to be patched again - they even have a weird patching system to try to work around the issue with code in views.
A better template language would actually limit the amount you can do in your view files to the bare minimum - something like mustache comes to mind. If you want to keep the views maintainable, easy to swap out, and easy to add alternatives to like json or XML as well as HTML, the aim should be to reduce the lines in your codebase by putting the filters, caching and logic around your views in helpers rather than inside your views.