Skip to content

Instantly share code, notes, and snippets.

@linhmtran168
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save linhmtran168/7e573be5eaa137824d6d to your computer and use it in GitHub Desktop.

Select an option

Save linhmtran168/7e573be5eaa137824d6d to your computer and use it in GitHub Desktop.
Handlebars Helper for If
// If condiational helper
Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
switch (operator) {
case '==':
return (v1 == v2) ? options.fn(this) : options.inverse(this);
case '===':
return (v1 === v2) ? options.fn(this) : options.inverse(this);
case '<':
return (v1 < v2) ? options.fn(this) : options.inverse(this);
case '<=':
return (v1 <= v2) ? options.fn(this) : options.inverse(this);
case '>':
return (v1 > v2) ? options.fn(this) : options.inverse(this);
case '>=':
return (v1 >= v2) ? options.fn(this) : options.inverse(this);
case '&&':
return (v1 && v2) ? options.fn(this) : options.inverse(this);
case '||':
return (v1 || v2) ? options.fn(this) : options.inverse(this);
default:
return options.inverse(this);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment