Or condition in Meteor.js template blocks

Is there a way to do the conditional "and" or "or" in the Meteor template? What I am trying to do is something like this:

{{#if isInRole 'ADMIN' || isInRole 'INSPECTOR'}}
  ...do some stuff
{{/if}}

      

with helpers provided by a third party package alanning:roles

. It seems like this has popped up several times in my coding with Meteor, and I can and did work around it, usually by duplicating block code, but it would be really nice if there was some way to handle OR or AND conditions without crazy fluctuations.

+3


source to share


1 answer


Meteor uses a rudder based spacebar. The rudders now have a direct path for logical operators.

You can do a little processing workaround by or

creatingTemplate.helper

Template.registerHelper("equals_or", function(param, arr) {
   arr = arr.split(",");
   if (arr.indexOf(param) !== -1) {
      return true;
   } 
   else {
     return false;
   }
});

      

Then in HTML you can do



{{#if equals_or isRole "ADMIN,INSPECTOR"}}
  ...do some stuff
{{else}}
   ...do some other stuff
{{/if}}

      

I may not have a perfect solution, but it gets the job done.

Check this answer .

+2


source







All Articles