@singuerinc


2014-01-02 by Nahuel Scotti | 1 min read

if condition Handlebars

  • #handlebars
  • #javascript
  • #nodejs

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