Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 239
user3475602 Avatar asked Jan 23 '26 12:01

user3475602


1 Answers

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.

like image 183
Akhar Avatar answered Jan 25 '26 18:01

Akhar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!