Skip to content

Instantly share code, notes, and snippets.

@jodaka
Forked from strathmeyer/handlebars.object_helpers.js
Last active December 17, 2015 14:49
Show Gist options
  • Save jodaka/5627074 to your computer and use it in GitHub Desktop.
Save jodaka/5627074 to your computer and use it in GitHub Desktop.
now works with latest version of handlebars
// HELPER: #key_value
//
// Usage: {{#key_value obj}} Key: {{key}} // Value: {{value}} {{/key_value}}
//
// Iterate over an object, setting 'key' and 'value' for each property in
// the object.
Handlebars.registerHelper( "key_value", function ( obj, options ) {
var buffer = "",
key;
for ( key in obj ) {
if ( obj.hasOwnProperty( key ) ) {
buffer += options.fn({
key: key,
value: obj[ key ]
});
}
}
return buffer;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment