Nested if else in macro

Wei Wang asked on June 4, 2020 20:28

Hi,

Can you do a nested if else in macro? What if I want to do else if for another condition?

Thank you Wei Wang

Correct Answer

Juraj Ondrus answered on June 5, 2020 08:52

It depends how complex the maxcro would be and how many conditions you want. For a few ones you can use e.g.:
{% x=FooValue; if (x=="foo"){"foo"} else {if (x=="foo2") {"foo2"} else {if (x="foo3") {"foo3"}}} #%}

But, if it should be more complex you should use the switch statement or, create a custom macro which will do the logic in the C# code.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on June 5, 2020 04:43 (last edited on June 5, 2020 04:48)

Sure you can. Post your code here. Perhaps you are looking for "switch" functionality? Here is a post on this topic.

1 votesVote for this answer Mark as a Correct answer

Wei Wang answered on June 5, 2020 14:02

Thank you all. I will try it later.

0 votesVote for this answer Mark as a Correct answer

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