user3475602
user3475602

Reputation: 1217

Using logical operators in Meteor's Spacebars

Is it possible to use logical operators in Spacebars (without template helpers)?

For example:

{{#if status == '0'}}
      Hello world.
{{/if}}

Unfortunately, I get the following error:

   While processing files with templating (for target web.browser):
   client/views/test.html:46: Expected identifier, number, string, boolean, null, or a sub expression enclosed in "(", ")"
   ...       {{#if status == '0'}}             ...
   ^

=> Your application has errors. Waiting for file change.

Upvotes: 3

Views: 799

Answers (1)

Akhar
Akhar

Reputation: 108

Spacebars can't into comparison, but you can use native underscore for it. Register it on client with:

Template.registerHelper('_', function(){
  return _;
});

and then use it like this:

{{_.isEqual status 0}}

It return true if status is 0 or false otherwise.

Upvotes: 6

Related Questions