Created
November 16, 2015 19:31
-
-
Save marcofugaro/790fc6821c5124e3d74b to your computer and use it in GitHub Desktop.
If operator in Handlebars.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
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); | |
} | |
}); | |
//usage | |
{{#ifCond var1 '==' var2}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment