4 ms·
> Mustache still has loops and conditionals (how those don't count as "logic" is beyond me) and you'll almost always have to use them. This is a bit esoteric,
by kneath 15y ago
> Mustache still has loops and conditionals (how those don't count as "logic" is beyond me) and you'll almost always have to use them.
This is a bit esoteric, because conditionals and loops are what most programmers are familiar with. I think the big difference for me is that it's not really a conditional or a loop but a context.
So when I say {{#var}} I'm saying within this context, output this partial — that partial can be a separate file or an inline HTML snippet. If that context doesn't exist, it doesn't get rendered (conditional). If that context is a collection of items, it renders each one (loop).
So, yeah. It's easier to say that they're conditionals and loops since that's what programmers are familiar with. But if you start thinking a bit different, you can see how there's really only one mode for Mustache: outputting stuff. You can't filter the output. You can't output parts of it. You can only output it or not.
If you spend some time with liquid (a templating language with logic, but with extremely similar syntax as mustache) you'll notice the difference. It's subtle, but (I think) important.
- baddox 15y agoI see your point, but I think it's really a continuum from templating languages with a lot of logic (e.g. ERB which gives you all of Ruby) to templating languages with less logic (e.g. Mustache or some hypothetical uber-minimal templating language). They're all languages that need to be learned, and they all "do logic," and I think a sweet spot should be the goal, not absolute minimalism. I've always been a big fan of Django templates, which are essentially a subset of Jinja2 templates.