Skip to content

Instantly share code, notes, and snippets.

@mikeobrien
Created October 8, 2012 22:53
Show Gist options
  • Save mikeobrien/3855468 to your computer and use it in GitHub Desktop.
Save mikeobrien/3855468 to your computer and use it in GitHub Desktop.
Handlebars conditional block helper
Handlebars.registerHelper('when', function (predicate, options) {
var declarations = '';
for (var field in this) declarations += field + ' = this.' + field + ',';
if (eval(declarations + predicate)) { return options.fn(this); }
});
{{#when 'admin || superUser'}}
crazy go nuts
{{/when}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment