Do you want to use Emarsys Scripting Language (ESL) to create dynamic and personalized content with your event or relational data? Are you familiar with the ESL basics and terminology but struggling with more complex scripts? Then this webinar is for you! In this session, we will look at advanced ESL examples and use cases, including if statements with event and relational data.
Use cases presented in the webinar
Use case 1. - Registration event
In this use case, we have set up a registration form asking for contact information, including an optional photo. We would like to send an email to a contact confirming their registration and utilizing personalization to show data that was entered into the form. Since the profile photo is optional, we would like to display that picture if the contact has uploaded it or a default one if an image is not available.
Here you can see 2 JSON samples, as well as the placeholders and the if statement used in the email.
- JSON samples:
{
"Customer":{
"first_name":"John",
"last_name":"Smith",
"email":"john.smith@lsl.com",
"address":"1234 Main Av",
"city":"Berlin",
"Zip":"98765",
"country":"DE",
"Profile_img":""
}
}
{
"Customer":{
"first_name":"John",
"last_name":"Smith",
"email":"john.smith@lsl.com",
"address":"1234 Main Av",
"city":"Berlin",
"Zip":"98765",
"country":"DE",
"profile_img":"https://suite16.emarsys.net/custloads/766447811/md_1443231.jpg"
}
}
- If statement:
{% if event.customer.profile_img %} {{ event.customer.profile_img }} {% else %} https://suite16.emarsys.net/custloads/766447811/md_815611.jpg {% endif %}
{{event.customer.first_name}}
{{event.customer.last_name}}
{{event.customer.email}}
{{event.customer.city}}
{{event.customer.zip}}
Here you can see the email with the personalization placeholders (described above) in the editor.
And this is how the email renders to the contact.
Use case 2. - Closest Store
In this use case, we have a Relational Data (RD) table with store information that we would like to use for personalizing our email. We decided to connect to the RD table using our customer's zip code in the contact record but since we only have stores on the East Coast, we need to hide the block if contacts:
- Don't have a zip code OR
- Don't have a zip code that matches a store in the RD table.
These are the placeholders for the email:
{{rds.rds_training.stores(contact.13)[0].name}}
{{rds.rds_training.stores(contact.13)[0].address}}
These placeholders are copied into the email template.
And this is what the contact will receive.
Use case 3. - Order Confirmation
In this use case, we would like to send an email to contacts confirming their purchase and to include all the items that they ordered, as well as some other personalized data such as order number and date.
- Here you can see the JSON file for this use case:
{
"customerName":"John",
"orderNumber":"3456789",
"Shipping":"5.00",
"deliveryDate":"15 May 2023",
"grandTotal":"230.00",
"Items":[
{
"productName":"LSL Men Jeans Summer Shirt",
"Quantity":"1",
"price":"$75.00",
"Color":"",
"image":"http://lifestylelabels.com/pub/media/catalog/product/cache/1/image/700x560/e9c3970ab036de70892d86c6d221abfe/i/s/istock_2917054_large.jpg"
},
{
"productName":"LSL Men Jacket College - Gray/White",
"Quantity":"1",
"price":"$150.00",
"color":"Gray/White",
"image":"http://lifestylelabels.com/pub/media/catalog/product/cache/1/image/700x560/e9c3970ab036de70892d86c6d221abfe/m/c/mct002.jpg"
}
]
}
- ESL placeholders:
{{event.customerName}}
{{event.orderNumber}}
{{event.deliveryDate}}
- Complete block with foreach loop and personalization:
{% foreach item in event.items %}
<tr>
<td bgcolor="{variables.bgcontent}">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="10"></td>
<td>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center">
<table cellpadding="0" cellspacing="0" width="100%" class="fw">
<tr>
<e-optional name="01 - Image">
<td width="138" class="rw40p vam pr5"><img e-editable="imageA_1" src="{{ item.image }}" width="138" border="0" style="display:block;" class="image"></td>
<td width="10" class="mh"></td>
</e-optional>
<td align="left" class="vam rw60p pl5 mvab">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<th class="fl vam">
<table cellpadding="0" cellspacing="0" width="100%">
<e-optional name="02 - Title">
<tr>
<td align="{variables.tah}" class="{variables.lhh} la2"><font e-editable="textA_1" class="ff fs22 fc2 fwn h3">{{ item.productName }}</font></td>
</tr>
<tr>
<td height="{variables.sephII}"></td>
</tr>
</e-optional>
<tr>
<td align="{variables.tab}" class="{variables.lhb} la1"><font e-editable="priceB_1" class="ff fs14 fc1 gf">{{ item.price }}</font></td>
</tr>
<tr>
<td height="{variables.sephII}"></td>
</tr>
{% if item.color %}
<tr>
<td align="{variables.tab}" class="{variables.lhb} la1"><font e-editable="textB_1" class="ff fs14 fc1 gf">Color: {{ item.color }}</font></td>
</tr>
{% endif %}
</table>
</th>
<th width="20" class="fl rhflexbcta"></th>
<th width="{variables.ctawidth}" align="right" class="fl vam">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="right">
<table cellpadding="0" cellspacing="0" bgcolor="{variables.ctabg}" width="100%" class="tcta1a">
<tr>
<td height="{variables.ctah}" align="center" class="lhp1 vam"><a href="" e-editable="urlA_1" target="_blank" style="padding:5px;" class="cta1a"><font e-editable="link_textA_1" class="ctaf">Lorem ipsum</font></a></td>
</tr>
</table>
</td>
</tr>
</table>
</th>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<e-optional name="99 - Spacing">
<tr>
<td height="{variables.sephVI}"></td>
</tr>
</e-optional>
</table>
</td>
<td width="10"></td>
</tr>
</table>
</td>
</tr>
{% endforeach %}
This is how the email template looks in the editor.
And this is how the rendered email will look like for the contact.