javascript - How to write handlebars if condition for integer values - Stack Overflow

How to write handlebars if condition for integer values. I've tried this below code but not workin

How to write handlebars if condition for integer values. I've tried this below code but not working.

{{#if (eq number '1')}}
        number 1    
{{else}}                
      another number    
{{/if}} 

How to write handlebars if condition for integer values. I've tried this below code but not working.

{{#if (eq number '1')}}
        number 1    
{{else}}                
      another number    
{{/if}} 
Share Improve this question edited Jan 16, 2017 at 8:44 Patsy Issa 11.3k5 gold badges56 silver badges74 bronze badges asked Jan 16, 2017 at 6:36 Vivekraj K RVivekraj K R 2,5582 gold badges24 silver badges41 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

For {{if (eq a b)}} helpers equivalent Javascript code is if (a === b), you can provide variables or values directly.

{{#if (eq number 1)}}
        number 1    
{{else}}                
      another number    
{{/if}}

The Mandrill mail service supports Handlebars and here it is possible to use "backticks" to evaluate an logical expression in a #if block:

{{#if `number < 0`}}
  negative
{{elseif `number == 42`}}
  the answer is 42
{{else}}
  positive and not 42
{{/if}}

I don't know if this possible in general, but you should try it out. It works fine for me.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745254072a4618850.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信