ESL belongs to the family of friendly and easy-to-learn scripting languages and can fulfill numerous functions for you.
The personalizations you can create with ESL can be more complex than the standard personalization options in SAP Emarsys.
How can you make more complex Personalization with ESL?
1. Using if
statements with foreach
An if
statement checks if something evaluates to true. If it does, the block content up to the (mandatory) {% endif %}
- with which you close the if statement - is processed. You can read more about if
statements here.
A foreach
loop will loop through each data listed in the ESL code and execute the ESL between the foreach
and endforeach
tags. You can learn more about foreach
here.
In this example we show our female customers the 3 best stores based on customer experience. And for our male customers we show the 3 closest stores. Even though we have data about 5 stores we’ll only list 3 of them with the help of foreach
.
{% if contact.5 == 2 %}
{% set shops = [{'name': 'Best shop', 'city': 'London'},{'name': 'Second Best shop', 'city': 'New york'},{'name': 'Third Best shop', 'city': 'San Francisco'},{'name': 'Fourth Best shop', 'city': 'Las Vegas'},{'name': 'Fifth Best shop', 'city': 'Budapest'}] %}
{% foreach item in shops limit 3 %}.
{{ item.name }}
{{ item.city }}
{% endforeach %}
{% elseif contact.5 == 1 %}
{% set shops = [{'name': 'Closest shop', 'city': 'London'},{'name': 'Second closest shop', 'city': 'New york'},{'name': 'Third closest shop', 'city': 'San Francisco'},{'name': 'Fourth closest shop', 'city': 'Las Vegas'},{'name': 'Fifth closest shop', 'city': 'Budapest'}] %}
{% foreach item in shops limit 3 %}
{{ item.name }}
{{ item.city }}
{% endforeach %}
{% endif %}
This is how the inserted code snippet looks in the email editor:
This is how it is rendered for female contacts:
This is how it is rendered for male contacts:
2. Using Twig filters
- A filter is a particular rule for an expression. To put it simply, you can modify the value of a variable when using it, but the actual value remains the same. You can learn more about Filters here.
- For example, in case you don’t have the customer’s first name, you can display a fallback text by using the default filter. So, if the first name field has no value in the system, display text "Friend" instead. The code looks like this:
{{ Contact.1|default('Friend') }}
The above ESL code will be rendered in an email like this:
3. Using Set variable
You can place a variable in a token and then use the value of the token for Personalization.
For example: In the previous example, we already used a Set Variable by stating that the foreach
should use the data that is saved in the “shops” token.
{% set shops = [{'name': Closest shop', 'city': 'London'},{'name': 'Second closest shop', 'city': 'New york'},{'name': 'Third closest shop', 'city': 'San Francisco'},{'name': 'Fourth closest shop', 'city': 'Las Vegas'},{'name': 'Fifth closest shop', 'city': 'Budapest'}] %}
4. Using Contact Data
SAP Emarsys accounts come with around 50 standard fields for storing contact data.
With ESL you can reference all the data fields that belong to every contact in the SAP Emarsys contact database and create personalized content based on them.
Here is an example of offering a discount to all your contacts that live in a specific city. We use the {{ contact.11 }}
ESL code snippet to reference the City contact data field in the email template.
And this is what the contact will see in their email:
Single-Choice system fields
There are Single-Choice system fields in the SAP Emarsys Contact Database. These are data fields where you can choose only a single value from multiple choices. For example the salutation, { contact.46 }
where the options are Mr/Ms/Mrs and you can only pick one. For a list of all the available values for the single-choice system fields, click here.
You can learn more about how to display the actual value of a single-choice system field in personalization tokens here.
There are also Multi-choice system fields. These fields can contain more than one value, contacts can select multiple values. For example: Interests { contact.0
}
.
The values for a given field ID (which represents the value of a field) in both single and multi-choice fields are only available in English.
5. ESL tokens
You can reference various data resources through ESL tokens which then will be populated with the contact’s corresponding data. To learn more about how to use ESL tokens, visit this article.