0

I'm trying to compare two values using Handlebar js like javascript if and else if else conditions in Handlebar js

for example:

var value = 124;

if(value == 124)
{
    console.log('This is red');
}
else if (value == 150)
{
    console.log('this is blue');
}
else
{
    console.log('No color selected');
}

same as in Handlebar js, how can we do it. I'm only able to see

{{#if field}} exp {{else}} exp {{/if}}

Please advise me. Thanks

Harish
  • 189
  • 2
  • 13
  • Take a look at https://stackoverflow.com/a/10884049/1552587 There seems to be an `{{else if field}}` in version 3+ – Titus May 11 '18 at 20:22
  • I did but this is not relevant to my issue, the condition should be == value, can I use a condition like this `{{#if value == '124'}} red {{elseif value == '150'}} blue {{else}} something {{/if}} – Harish May 11 '18 at 20:34
  • Take a look at https://stackoverflow.com/q/8853396/1552587 In any case, why use an `else if` for `==` conditions or why do this in the template in the first place ? – Titus May 11 '18 at 20:40
  • @Harish did you try `{{#if value == '124'}} red {{else if value == '150'}} blue {{else}} something {{/if}}` like Titus suggested? Are you using Handlebars > 3.0.0? – Andy May 11 '18 at 20:52
  • tried but not relevant to me, my case is completely different, value coming from other application which will we check using this condition, but every single time returns one value, whatever, should verify with the condition and assign a variable value like red, blue or something like that. so – Harish May 11 '18 at 21:09

0 Answers0