What are the benefits of logic-less templates like {{Mustache}}?
I've seen lots of talk about {{mustache}}, and I've used it in a few projects. Sometimes it's a great fit, and sometimes I find myself fighting against it. But I don't have strong feelings about it either way. What are the reasons that people love it?
{{mustache}} is great since it is language independent. You can utilize same mustache template with different languages.
For example, you'd like to AJAX-ify your web application, which means a lot of (even whole) HTML partials are generated by JavaScript. At the same time, you want your web page to be search engine friendly and backward compatible. If your web app is accessed by search engine crawler or user-agent without javascript support, your server just respond pure HTML partials generated by server side language (PHP, ruby etc).
Without Logic-less template such as mustache, you have to write same logic of rendering HTML partials in both JavaScript and server-side language. This is redundancy.
With the help of mustache, you just make sure your data model can generate JSON understandable to mustache template. The data can be rendered into HTML in server side or client side without writing duplicate code.
The main reason we are shifting to logic-less templates in general is clear separation of design and data. Once a software grows larger than a certain size, adding new features becomes painful if your templates contain ANY kind of logic. Yes if you are already doing clean logic-less templates in your existing language then you may not need to shift to Mustache at all. We chose Mustache because like Twitter, Facebook and many others we needed basic rendering when JS was not available. This is done from our PHP back-end directly, but the template files are still the same. I can you show you the code right now, but once we release http://forums.com version 2 we will document what we have done.
While less logic in templates is good I think Mustache is still missing features to be truly useful. For example: if tags .One thing is business logic and another is display logic. Printing a table with alternate color rows is a display matter that is best adressed with counters and if /else tags. I think Handlebars, which is a mustache extension, is a better templating solution. ( it is only available client side now).
Handlebars can be made to run on the server-side with a Server JS engine such as V8, LinkedIn is using http://linkedin.github.com/dustjs/, which probably supports similar constructs that Handlebars started to