Hi
I am trying to work out how to create a nested IF statement.
e.g.
{% If custom.text.box == ‘A’%}
Case A
{% else if custom.text.box == ‘B’ %} -> This is the part that doesn’t work
Case B
{% else %}
Case C
{% endif %}
Is this possible with the if formula or do I need an alternative one?
Thanks
Fay
Hi @faybordbar,
Welcome to the Silverfin community! Hopefully you will find a lot of useful information here and on our developer website: https://developer.silverfin.com/docs.
As for your question, when you create an if
statement (or any other control flow statement, https://developer.silverfin.com/docs/control-flow) there are a few thing to bare in mind:
-
No capitalisation should be used in keywords (in this case no capitalisation of if
);
-
There is a keyword elsif
which is one word (used for your second statement);
-
Please do not use reserved words in naming your variables, functions, labels (for example text
since it is a variable type in liquid). You can call it some_text
or text_1
, etc. Useful link: Naming variables
-
nested if
statement is an if
statement inside which there is another if
statement (an example provided below, usually different logic is checked in each statement):
{% if custom.some_text.box == ‘A’ %}
Case A
{% elsif custom.some_text.box == ‘B’ %}
Case B
{% else %}
{% if custom.some_text.box != blank %}
Not blank
{% else %}
Blank
{% endif %}
{% endif %}
Let us know if you need any more help or if you have any more questions. And good luck in your coding journey!
Regards,
Dasha