Skip to content

Instantly share code, notes, and snippets.

@kdauzickas kdauzickas/helper.js
Last active Dec 18, 2015

Embed
What would you like to do?
Handlebars {{#or}} helper. When you need variable amount of values to OR together.
// var context = {foo: true}
// {{#or foo bar baz}}Yup{{else}}Nope{{/or}} -> Yup
// {{#or bar baz}}Yup{{else}}Nope{{/or}} -> Nope
Handlebars.registerHelper('or', function() {
var fncType = toString.call(function(){});
for (var i = 0; i < arguments.length - 1; i++) {
var arg = arguments[i];
if (toString.call(arg) === fncType) {
arg = arg.call(this);
}
if (arg && !Handlebars.Utils.isEmpty(arg)) return arguments[arguments.length - 1].fn(this);
}
return arguments[arguments.length - 1].inverse(this);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.