Skip to content

Instantly share code, notes, and snippets.

@virasak
Last active August 29, 2015 01:06
Show Gist options
  • Save virasak/5c0d1d9229bd5936b9ac to your computer and use it in GitHub Desktop.
Save virasak/5c0d1d9229bd5936b9ac to your computer and use it in GitHub Desktop.
Handlebars Subexpressions
{ "foo" : "Foo", "bar": "Bar"}
Handlebars.registerHelper('eq', function (a, b) {
return a == b;
});
Handlebars.registerHelper('neq', function (a, b) {
return a != b;
});
Handlebars.registerHelper('ge', function (a, b) {
return a >= b;
});
Handlebars.registerHelper('gt', function (a, b) {
return a > b;
});
Handlebars.registerHelper('gt', function (a, b) {
return a > b;
});
Handlebars.registerHelper('all', function () {
var args = Array.prototype.slice.call(arguments);
var options = args.pop();
var i = 0;
while (i < args.length) {
if (!args[i]) return options.inverse(this);
i++;
}
return options.fn(this);
});
Handlebars.registerHelper('any', function () {
var args = Array.prototype.slice.call(arguments);
var options = args.pop();
var i = 0;
while (i < args.length) {
if (!!args[i]) return options.fn(this);
i++;
}
return options.inverse(this);
});
{{#all (eq foo 'Foo') (eq bar 'Bar') }}
Foo
{{else}}
Bar
{{/all}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment