Code nesting allows you to use more complex structures in your marketing campaigns by using tags within tags or by fine-tuning your conditions. For example, you can have a condition within a foreach loop. So you don’t have to close an ESL tag before opening another.
Code nesting means layering a piece of code by adding inner blocks to it. ESL supports code nesting.
Nested code should always start with an if
statement and each one should be closed with an endif
tag.
Example
{% if contact.17 == 28 %}
{% if contact.14 == 65 %}
Job offers in Germany
{% else %}
International job offers
{% endif %}
{% else %}
{% if contact.14 == 65 %}
Training session in Germany
{% else %}
International training session
{% endif %}
{% endif %}
Where:
- Line 1 means that the contact is unemployed (
contact.17
is the job position field and the ID28
stands for unemployed), - Line 2 means that the contact’s country (
contact.14
) is set to Germany (ID65
), - If the contact meets the first 2 conditions, then job offers will be displayed in Germany for the contact.
- Lines 4-6 define that if the contact does not live in Germany, then international job offers will be displayed for this contact.
- Lines 7-9 define that if the contact is not unemployed but lives in Germany, then German training sessions will be offered to this contact.
- Lines 10-12 define that if the contact is not unemployed and does not live in Germany, then international training sessions will be offered to this contact.