Skip to content

Instantly share code, notes, and snippets.

@torstenfeld
Created August 11, 2013 16:13
Show Gist options
  • Save torstenfeld/6205523 to your computer and use it in GitHub Desktop.
Save torstenfeld/6205523 to your computer and use it in GitHub Desktop.
Handlebars.js if-condition helper
Handlebars.registerHelper('ifCond', function(v1, operator, v2, options) {
switch (operator) {
case '==':
return (v1 == v2) ? options.fn(this) : options.inverse(this);
break;
case '!=':
return (v1 != v2) ? options.fn(this) : options.inverse(this);
break;
case '===':
return (v1 === v2) ? options.fn(this) : options.inverse(this);
break;
case '!==':
return (v1 !== v2) ? options.fn(this) : options.inverse(this);
break;
case '<':
return (v1 < v2) ? options.fn(this) : options.inverse(this);
break;
case '<=':
return (v1 <= v2) ? options.fn(this) : options.inverse(this);
break;
case '>':
return (v1 > v2) ? options.fn(this) : options.inverse(this);
break;
case '>=':
return (v1 >= v2) ? options.fn(this) : options.inverse(this);
break;
default:
return options.inverse(this);
break;
}
//return options.inverse(this);
});
@torstenfeld
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment