Reputation: 2476
In mustache, you iterate like this:
{{#items}}
<div>The item {{item}}</div>
{{/items}}
In handlebars.js, there is a block helper each
that lets you use an alternative syntax:
{{#each items}}
<div>The item {{item}}</div>
{{/each}}
Assuming I'm using handlebars, why would I use one syntax instead of the other? Which do you use, and why?
In Yehuda Katz's blog post introducing handlebars, he talks about how block helpers allow him to remove the special casing needed to implement iteration in normal mustache syntax. Is this the only reason the each
syntax exists?
Upvotes: 3
Views: 1074
Reputation: 2476
I ended up asking Yehuda on Twitter. Here's his reply:
"two off the top of my head: performance and it's easier to understand"
Upvotes: 7