if-else-if

Jakaria al Mahmud asked on April 18, 2018 12:52

Can I write a elseif in Macro syntax ? Like: {% if(a == "value1"){ "some test 1" }elseif(a=="value2"){ "some test 2" }else{ "some test 3" } %}

Correct Answer

Prashant Verma answered on April 18, 2018 13:32

Hi Jakaria,

Yes you write it in macro.

can you brief about what exactly you want to implement because it depends on the transformation type. For most of them (like Text/XML) you can simply use this one

{%
if (...) {
...
}
else {
...
}

OR

you can use ternary operator like below.

{%(a=="value1")? "some test 1": a=="value2"? "some test 2": "some test 3"%}

Thanks

Happy to help

0 votesVote for this answer Unmark Correct answer

Recent Answers


Vukasin Andjelic answered on April 18, 2018 13:18

Hi Jakaria, I think you need to do on this way

{% 
if(a == "value1"){ "some test 1" }
else{
    if(a=="value2"){ "some test 2" }
    else{ "some test 3" }
}
%}

Best regards

0 votesVote for this answer Mark as a Correct answer

Jakaria al Mahmud answered on April 18, 2018 13:29

Thanks @Vukasin, I also use that way, but if we will able to use elseif, syntax will be more easy and simple.

Regards

0 votesVote for this answer Mark as a Correct answer

Jakaria al Mahmud answered on April 18, 2018 13:42 (last edited on April 18, 2018 13:51)

Hi @prashant, I'm just going to write it on "Recipient emails" filed in a BizForm form. Which one is best 1st one or 2nd one?

Regards,

1 votesVote for this answer Mark as a Correct answer

Prashant Verma answered on April 18, 2018 13:55

Hi Jakaria,

2nd one is more clean and faster.

0 votesVote for this answer Mark as a Correct answer

Jakaria al Mahmud answered on April 18, 2018 13:57

Hi Prashant, Thanks a lot for your help :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.