Conditional “if statement” helper for Handlebars.js

后端 未结 2 1087
深忆病人
深忆病人 2021-02-04 05:21

I am trying to write a conditional if statement helper for Handlebars.js. Essentially, I want to put an \"active\" class on a link if it is the Apply Now page.

2条回答
  •  情深已故
    2021-02-04 06:12

    NOTE: block(this) in the helper will not work anymore. Instead, use block.fn(this)

    e.g.

     Handlebars.registerHelper('isApplyNow', function(block) {
        if (this.title === "Apply Now") 
          return block.fn(this);
        else 
          return block.inverse(this);
     });
    

提交回复
热议问题