Hoy: Handlebars/Javascript, if condition helper
handlebars.registerHelper("ifCond", function (v1, cond, v2, opt) {
switch (cond) {
case "==":
return v1 == v2 ? opt.fn(this) : opt.inverse(this);
case "===":
return v1 === v2 ? opt.fn(this) : opt.inverse(this);
case "<":
return v1 < v2 ? opt.fn(this) : opt.inverse(this);
case "<=":
return v1 <= v2 ? opt.fn(this) : opt.inverse(this);
case ">":
return v1 > v2 ? opt.fn(this) : opt.inverse(this);
case ">=":
return v1 >= v2 ? opt.fn(this) : opt.inverse(this);
default:
return opt.inverse(this);
}
});
Ejemplo:
#ifCond blog '===' 'singuerinc'
<node>blog ok</node>
/ifCond