3 ms·
With a bit of discipline, you can use ERB and still maintain separation of concerns. I think everyone knows that the controllers should do most of the work gett
by baddox 15y ago
With a bit of discipline, you can use ERB and still maintain separation of concerns. I think everyone knows that the controllers should do most of the work getting stuff out of the models and into a useful form, and the ERB templates should just drop that stuff into the right spots in the HTML, but too often it's just way too convenient to do something substantial (like hit the db, sort a collection, etc.) inside the template.
I guess the idea behind Mustache and other similar minimal templating engines is to force the discipline that everyone knows they should have. Personally, I think the claim that designers should be able to write templates with zero programming knowledge is a pipe dream; 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.
- 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.