I don't understand why logic in client-side templates is so anathema. I can branch based on a value in a server-side view, why not client-side?
I'm currently using jQuery Templates (which is obviously sub-optimal) just because I would like some basic logic in my templates. This looks exactly like what I need.
I've found Handlebars to be the sweet spot for templating.
Mustache is too limited for my taste and seems to force me to pre-render parts of the HTML, so that the template doesn't actually contain all of it. Or there will be many small templates, being combined by some logic that's not clearly visible when looking at the template code.
Handlebars has just enough flexibility to allow me to put all HTML in a single template, using {{#if}} and {{#each}} to navigate the data. Then I can add helpers and new data model properties to add formatting and logic.
The sweet spot of logic for me means that I only use a single identifier in the {{#if}}, such as {{#if adminAccess}}, and make "adminAccess" a property of the data model. So then whoever reads the template is not trying to parse huge logical expressions in the if clauses, but only sees their results assigned to identifiers.
(Earlier, Mustache was even more limited, because it didn't have the concept of "this" ({{.}}) when iterating arrays. As I understand, this has later been fixed.)
Templates should be about how things look like. You'll need some minor capabilities to style things dependent on values, but it's a slippery slope: You start out with branch on "exists", then later see that you need to style every even row in a table. Next project you need to style every third row and decide "oh, I can generalize that". And then you end up with a full math implementation. And wouldn't it be awesome if we could branch depending on the length of a value? You start hacking and the next thing you know when you wake up in the morning is that your template language is Turing complete. Now you have another language to learn.
It's far easier to make a cut at "no logic apart from boolean checks" and then use a proper client-side framework such as backbone if you need full view logic on the client. It separates concerns and makes clear where logic is supposed to reside. I love separation of concerns!
> It's far easier to make a cut at "no logic apart from boolean checks" and then use a proper client-side framework such as backbone (...)
That works if you are fine with offsetting all (or most) of your presentation logic to client side. But not every web application is the glorified single-page web app, or has significant amount of on-page interaction that would warrant employing a full stack MVC framework on the client side.
> Templates should be about how things look like.
But also what elements are those things built from. Despite attempts at logic-less templates, the presentation layer still must contain some logic and I see no reason to not apply normal coding principles - most notably DRY - to that logic. That's why I consider it very important for a templating engine to allow for reusing things, and splitting things into parts. Here's where some engines really shine (Jinja immediately comes to mind, followed by Underscore or jQuery templates) and others... not so much.
On-page interaction does not require a templating language with logic. You can just as easily calculate the required values in your javascript and then pass the objects on to Mustache. That's a tangential point.
I fully agree with you that having some logic in a template language has its appeal. At first glance it sounds like a good idea (oh, I don't have to go back to the code to calculate that value, nice!) However, as I said, it's a slippery slope and depending on where you and your project end up, you may pay a dire price for that. In the end, inevitable, some part of your logic ends up in the template. (Been there, done that, been burnt)
Mustache/Handlebars allows for most of what you want - reuse things, split things into parts (templates can include other template) without including logic and thus creates a barrier that you cannot cross. It forces you to adhere to best practices.
You don't want logic in your templates so you can share the templates both client and server-side. For example, in my Backbone.js app, I use the same Handlebars templates on the server when serving content to the search engine crawlers since they can't run the JavaScript.
I'm currently using jQuery Templates (which is obviously sub-optimal) just because I would like some basic logic in my templates. This looks exactly like what I need.