JSFiddle - React, Tailwind, and code Playground
by bendog
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0.beta6/handlebars.min.js"></script>
Handlebar test
<script id="compare-template" type="text/x-handlebars-template">
<p>
{{#compare 5 6 operator="=="}}
5 is equal to 6
{{^}}
5 is not equal to 6
{{/compare}}
<br/>
{{#compare 6 6 operator="=="}}
6 is equal to 6
{{^}}
6 is not equal to 6
{{/compare}}
</p>
</script>
JavaScript
Handlebars.registerHelper('compare', function(lvalue, rvalue, options) {
if (arguments.length < 3)
throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
operator = options.hash.operator || "==";
var operators = {
'==': function(l,r) { return l == r; },
'===': function(l,r) { return l === r; },
'!=': function(l,r) { return l != r; },
'<': function(l,r) { return l < r; },
'>': function(l,r) { return l > r; },
'<=': function(l,r) { return l <= r; },
'>=': function(l,r) { return l >= r; },
'typeof': function(l,r) { return typeof l == r; }
}
if (!operators[operator])
throw new Error("Handlerbars Helper 'compare' doesn't know the operator "+operator);
var result = operators[operator](lvalue,rvalue);
if( result ) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
var source = $("#compare-template").html();
var template = Handlebars.compile(source);
var html = template({});
$('body').append(html);