简体   繁体   中英

meteor create custom 'if/else'

I haven't used meteor for a while, back in the day I was able to create custom handlebars helpers like

{{#ifCond this.a "a"}}
   ...
{{else}}
   ...
{{/ifCond}}

and define a helper like this:

Handlebars.registerHelper('ifCond', function(v1, v2, options) {
  if(v1 === v2) {
    return options.fn(this);
  }
  return options.inverse(this);
});

Example from this SO Question: Stackoverflow Question

Since meteor introduced new spacebars features this doesn't seem to work anymore, anybody any ideas?

I think it has something to do with this: "Custom Block Helpers" : Spacebars docu

This was the closest I could get, but it's not too bad:

Handlebars.registerHelper('ifCond', function(v1, v2, options) {
  if(v1 === v2) {
    return true;
  }
  return false;
});


{{#if ifCond this.Equipment '==' 'Assistive'}}
true
{{else}}
false
{{/if}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM