Last active
August 29, 2015 14:03
-
-
Save be-hase/c43423aa9f6522735ce6 to your computer and use it in GitHub Desktop.
Handlebars.js "extended if"
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("if?",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 eval(""+v1+operator+v2)?options.fn(this):options.inverse(this); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment