5 ms·
Conversely, my experience is that there are very good reasons not to use Mustache (and instead use Handlebars etc.) — there are just too many limitations that f
by kapowaz 14y ago
Conversely, my experience is that there are very good reasons not to use Mustache (and instead use Handlebars etc.) — there are just too many limitations that force you to push commonly required functionality into an awkward place within the application stack.
Plus there's the whole thing that ‘logic-less’ is a big white elephant: templates need logic, or they quickly become unmanageably bloated and un-DRY. Being able to iterate and conditionally branch are fundamentals essential to templating languages, and so whilst Mustache is an interesting starting point, it's usually not the best solution.
Of course, the one benefit Mustache does have is parsers in lots of languages, allowing you to share templates across client and server-side — it'd be great if somebody were to invest time in producing (say) a Ruby version of Walrus, as it looks like a very useful tool from reading through the docs.
- moe 14y agoI agree wholeheartedly. Logic-less templates are a red herring and I cringe every time I enter a project where someone has drunken the Kool-Aid. There's the rare fringe use-case where logic-less templates make sense, e.g. when you need to accept templates from untrusted sources (user editable) or when you really can re-use them across tiers to a significant degree. In pretty much all projects neither is the case. Instead, they quickly turn into a ball on a chain that constantly gets in the way and causes more problems than it solves. This is my experience from encountering them in nearly a dozen projects and from having fallen for the temptation more than once myself.
- laserDinosaur 14y ago"templates need logic, or they quickly become unmanageably bloated and un-DRY" Maybe I'm misunderstanding this, but you can do some fancy stuff with handlebars.js. You can 'foreach' through a json collection right in the template, 'if' 'else' statements and a whole whack of other cool little logic statements. So far I've not found anything I can't do in handlebars that I could do generating the page server side. Maybe I'm missing some more advanced cases or misunderstanding the term 'logic-less'?
- kapowaz 14y agoI think maybe you got the wrong end of the stick; I'd always rather go with Handlebars.js over Mustache. Plus you get nice things like helpers. Walrus looks to take it to a whole new level though, so I'm itching to try it out.
- spullara 14y agoI'm not sure where you get the idea that you can't iterate and conditionally branch in Mustache. It is just far more declarative than writing a for loop or an if statement.
- kapowaz 14y agoMy point wasn't that Mustache lacks these features, but that they're so essential as to make not handling them well feel like an omission. It needlessly bloats your template code to have to write within these constraints, and for what benefit? Some nebulous ‘logic-less’ purity?
- spullara 14y agoBut it does have those features, so, I don't get it. What are you trying to say? As for bloated template code? I really don't know what you are talking about. Perhaps you just haven't seen well written mustache templates. My startup, Bagcheck, and Twitter (where I now work) have switched completely to Mustache. It really does work well if you use it properly.