Skip to content

Instantly share code, notes, and snippets.

View strathmeyer's full-sized avatar

Eric Strathmeyer strathmeyer

View GitHub Profile
// original each helper
Handlebars.registerHelper('each', function(context, options) {
var fn = options.fn, inverse = options.inverse;
var ret = "";
if(context && context.length > 0) {
for(var i=0, j=context.length; i<j; i++) {
ret = ret + fn(context[i]);
}
} else {
@burin
burin / each_with_index.coffee
Created June 27, 2011 14:33
each_with_index handlebars helper, adds an {{index}} prop accessible from within the block
Handlebars.registerHelper 'each_with_index', (array, fn) ->
buffer = ''
for i in array
item = i
item.index = _i
buffer += fn(item)
buffer