Reputation: 7988
I can't figure out a way to do something like this in a Template with Meteor and Handlebars:
{{#if var1 == var2}}
{{/if}}
I've also set up the Meteor Handlebars Helpers and this seems not to work too while it should:
{{#if $eq var1 var2}}
{{/if}}
So what is your proper way to compare two variables with Handlebars in a Template?
EDIT: In fact, this seems to go beyond the Handlebar ideology which is that there should be no logic in templates.
Upvotes: 2
Views: 788
Reputation: 2474
For now this is not as easy as you might aspect. I thought i have read that this is maybe a feature in meteor 1.0.
You have the 3 following possibilities:
html:
<template name="stuff">
{{#if isTrue}}
...
{{else}}
...
{{/if}}
</template>
js:
Template.stuff.helpers({
isTrue: function () {
return var1 === var2;
}
});
Another possibility is to provide an own handlebars helper:
html:
{{compare "var1" "var2"}}
js:
Handlebars.registerHelper('compare', function(var1, var2) {
return var1 === var2;
});
Or you use any other Handlebars-helper package where someone already did the work for you. I dont know the package you used, so i cant give a detailed solution about your problem but maybe you get a nice view of how this can be realised.
Upvotes: 3