Created
August 11, 2013 16:13
-
-
Save torstenfeld/6205523 to your computer and use it in GitHub Desktop.
Handlebars.js if-condition helper
This file contains hidden or 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); | |
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
taken from http://stackoverflow.com/a/16315366/1271692