In anif
statement, the only mandatory lines are{% if xy == something %}
and{% endif %}
. The lines {% else %}
and {% elseif %}
are useful, but optional only.
{% elseif %}
is used exclusively for checking another condition after the previous one has failed. If you do not have a second condition to check, you should be using {% else %}
insted of {% elseif %}
.
Important: Please always use {% elseif %}
with a preceding if
statement. You don’t need to close the preceding if
statement with {% endif %}
. You can use as many {% elseif %}
lines as you need.
In the following example, we will show you how to use the {% elseif %}
statement to show different products to contacts based on their gender.
{% if contact.5 == 1 %}
Check out our vast selection of jackets and ties.
{% elseif contact.5 == 2 %}
Check out our vast selection of skirts and shorts.
{% else %}
Check out our vast selection of T-shirts and jumpers.
{% endif %}
In VCE this is how the template will look like:
This is what female contacts will see:
And this is what male contacts will see:
And this is what contacts will see if their chose the Prefer not to say option:
In another example you can use ESL variables with the {% elseif %}
statement to define someone's zodiac sign for their horoscope.
In the Emarsys Contact database, Contact field #4 contains the contact’s birthdate, so we use this field in the if
statement.
We use the localized_date
filter to ensure that the birth date and time specifying the zodiac sign's applicability are formatted the same way. To read more about localized_date
filter, click here and here.
<>
characters should not be added in the VCE editor, instead put them in an ESL snippet and add it to the template.
Hey {% if contact.4|localized_date('en','Mdd') > 1221 or contact.4|localized_date('en','Mdd') < 120 %}
Capricorn
{% elseif contact.4|localized_date('en','Mdd') > 1122 %}
Sagittarius
{% elseif contact.4|localized_date('en','Mdd') > 1022 %}
Scorpio
{% elseif contact.4|localized_date('en','Mdd') > 922 %}
Libra
{% elseif contact.4|localized_date('en','Mdd') > 822 %}
Virgo
{% elseif contact.4|localized_date('en','Mdd') > 722 %}
Leo
{% elseif contact.4|localized_date('en','Mdd') > 620 %}
Cancer
{% elseif contact.4|localized_date('en','Mdd') > 520 %}
Gemini
{% elseif contact.4|localized_date('en','Mdd') > 419 %}
Taurus
{% elseif contact.4|localized_date('en','Mdd') > 320 %}
Aries
{% elseif contact.4|localized_date('en','Mdd') > 218 %}
Pisces
{% elseif contact.4|localized_date('en','Mdd') > 120 %}
Aquarius
{% endif %}, it's time to celebrate
This how the ESL snippet will look like in VCE:
And this is how the email will be rendered for a contact whose zodiac sign is Virgo: