I am using Ember with Handlebars template
How can I get the following support in Handlebars ?
{{#if response.someCount> 0}}
Would I have to add some mapping attribute in Controller to achieve this ?
I am using Ember with Handlebars template
How can I get the following support in Handlebars ?
{{#if response.someCount> 0}}
Would I have to add some mapping attribute in Controller to achieve this ?
You need helper for that, for example:
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);
}
});
And then in Your template:
{{#compare response.someCount 0 operator = ">"}}
// Some code...
{{/compare}}
Sorry can't remember from where I toot that code, but it runs flawlessly in one project for over the year.