Handlebars.registerHelper('if_gt', function (a, b, opts) { return a > b ? opts.fn(this) : opts.inverse(this); }); Handlebars.registerHelper('if_eq', function (a, b, opts) { return a == b ? opts.fn(this) : opts.inverse(this); }); Handlebars.registerHelper('if_ne', function (a, b, opts) { return a != b ? opts.fn(this) : opts.inverse(this); }); Handlebars.registerHelper('if_or', function () { var opts = arguments[arguments.length - 1]; var result = false; for (var i = 0; i < arguments.length - 1; i++) { result = result || arguments[i]; if (result) break; } return result ? opts.fn(this) : opts.inverse(this); }); Handlebars.registerHelper('if_and', function () { var opts = arguments[arguments.length - 1]; var result = true; for (var i = 0; i < arguments.length - 1; i++) { result = result && arguments[i]; if (!result) break; } return result ? opts.fn(this) : opts.inverse(this); }); Handlebars.registerHelper('if_cond', 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); default: throw 'Invalid operator ' + operator; } }); Handlebars.registerHelper('substr', function (s, start, length) { return new Handlebars.SafeString(s.toString().substr(start, length)) }); Handlebars.registerHelper('switch', function (value, options) { this._switch_value_ = value; this._switch_break_ = false; var html = options.fn(this); delete this._switch_break_; delete this._switch_value_; return html; }); Handlebars.registerHelper('case', function () { if(!this.hasOwnProperty('_switch_value_')) throw 'case outside switch'; var args = Array.prototype.slice.call(arguments); var options = args.pop(); var caseValues = args; if (this._switch_break_ || caseValues.indexOf(this._switch_value_) === -1) { return ''; } else { if (options.hash.break === true) { this._switch_break_ = true; } return options.fn(this); } }); Handlebars.registerHelper('default', function (options) { if(!this.hasOwnProperty('_switch_value_')) throw 'default outside switch'; if (!this._switch_break_) { return options.fn(this); } });