Skip to content

Instantly share code, notes, and snippets.

@zwily
Created January 5, 2013 04:25
Show Gist options
  • Save zwily/4459743 to your computer and use it in GitHub Desktop.
Save zwily/4459743 to your computer and use it in GitHub Desktop.
making iterating in handlebars suck less
# Used like this:
# {{#foreach "zone" in data.availability_zones}}
# <th>{{zone}}</th>
# {{/foreach}}
Handlebars.registerHelper "foreach", (keyword, blah, collection, ctx) ->
buffer = ""
copy = _.clone(this)
_.each collection, (i) ->
copy[keyword] = i
buffer += ctx.fn(copy)
buffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment