News for hackers. Stuff that matters.
Re:Walrus.js - Mustache on steroids by sophacles on Thursday June 28, 2012 @10:49AM (#4171937)
I like mustache a lot. Particularly because it just works for every language I use, and a huge number of the languages I might use. But it does have pain points (lots of little templates, weird include behavior, some uneccessary repetition, etc).

I don't think that adding logic, filters, etc explicitly to the templates is the right answer. Such things tend to accelerate and encourage big ball of mud apps (in my experience ymmv). It also makes it harder to have a consistent cross-platform experience. I really think a better solution might be to have a simple callback mechanism. So for instance, a tag:

   {{*foo}}
Would result in the renderer looking in the context dictionary for a key "foo". If the value for that key is callable, it calls the function (with the context dictionary as an argument), and replaces the tag with the return string of the function.

That's it. This can mitigate many of the pain points of the templates, while still making consistent implementations across languages easy.

It is still a bit tricky in the "templates are the same on client and server" case, because then you need to implement a function twice (potentially), but I think I would rather do that than descend into some of the templates with logic horrors I've seen (and written myself sadly).

There are no comments on this comment yet.