From 8f502ffbe76b49ebf4d11bd19b3f094e2c483d6a Mon Sep 17 00:00:00 2001 From: wycats Date: Sun, 19 Dec 2010 00:06:55 -0800 Subject: [PATCH] Add #each and #if built-in helpers for more readable iteration and conditionals --- lib/handlebars/compiler.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/handlebars/compiler.js b/lib/handlebars/compiler.js index 96ae36ab..2ffd8296 100644 --- a/lib/handlebars/compiler.js +++ b/lib/handlebars/compiler.js @@ -77,6 +77,28 @@ Handlebars.registerHelper('blockHelperMissing', function(context, fn, inverse) { }, function(context, fn) { return fn(context) }); + +Handlebars.registerHelper('each', function(context, fn, inverse) { + var ret = ""; + + if(context.length > 0) { + for(var i=0, j=context.length; i