Created
May 14, 2012 21:38
-
-
Save scttnlsn/2697405 to your computer and use it in GitHub Desktop.
Handlebars object iteration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Handlebars.registerHelper('eachobj', function(object, options) { | |
var buffer = ''; | |
var empty = true; | |
for (var key in object) { | |
buffer += options.fn({ key: key, value: object[key] }); | |
empty = false; | |
} | |
if (empty) { | |
return options.inverse(this); | |
} else { | |
return buffer; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment