Skip to content Skip to main navigation Skip to footer

Using TWIG Block inside Email Templates with Advanced Scripting

Inside the Aritic PinPoint email template editor, you can use advanced scripting techniques like conditions, loops, etc to format and personalize email templates.

If you already know details about your contact (like country, gender, or more), you will need different content for your email that is relevant based on the contact information. However, by creating multiple emails based on each information, you can design one with conditions coded in it.

Another instance is when you want to add dynamic content to your email. Let’s say you are designing a cart abandonment email and you want to send them content that shows the exact items added to their carts. Instead of going over each contact’s cart and creating an email, you can just push the cart content in JSON format to your contact via API. It then iterates through your template to pull in pictures, names, and prices of the items for each one.

Add TWIG code blocks inside email templates:

1.Go to Aritic PinPoint Dashboard > Assets > Email Templates > Design New Template.

TWIG code blocks work inside the code mode and HTML editor blocks in code inside the email template.

2. Create an email and add the TWIG template between the special tags, as shown below:

{%TWIG_BLOCK%}
Here you add your template TWIG.
{%END_TWIG_Block%}

– You can load reusable TWIG snippets from Dynamic Content entities.
– TWIG now comes with extended functions and filters.

Uses of TWIG code blocks:

You don’t need any additional configuration inside Aritic PinPoint, to use this feature. The text between {%TWIG_BLOCK%} and {%END_TWIG_Block%} in your email template code block is treated as the TWIG block.

For detailed information, read through the official documentation of TWIG to understand all the syntax and capabilities.

Avoid multiple scenarios of copy-paste by adding the include() function in your templates. Add reusable bits of the template into the HTML block entity and keep using it in your main email templates.

P.S.: The context is shared along with the included template. This means that each variable available outside will also be available in the included snippet.

Check the table below to understand which variables are exposed to context. Also, you will see that it contains a list of additional functions and filters that are available. Please note, all standard library of filters/functions/tags are as per official TWIG documents.

Example 1: Default Scenario

You want to add an extra paragraph about London’s weather for people in that area.

1. Go to Aritic PinPoint Dashboard > Assets > Email Templates > Design New Template.
2. Open the editor to format the HTML code.

3. Add the following snippet inside your template:

{% TWIG_BLOCK %}
Hi {{lead.firstname}},
{% if lead.city == 'London' %}
What a great weather is in London this week!
{% endif %}
Main letter content goes here
{% END_TWIG_BLOCK %}

Example 2: To Render structured data

You want to remind your customers about a purchase that is pending (i.e. cart abandonment).

Assuming that you have already integrated your eCommerce platform, you already have contact information pushed into Aritic PinPoint in the custom field ‘cart’.

Here let’s assume that the cart information is in JSON and it has the below format:

[
{"sku": "1334526", "name": "My product 1"},
{"sku": "8434061", "name": "My product 2"}
]

Now, to render all items, your modified code should look somewhat like this:

{% TWIG_BLOCK %} 
    {% set cart = lead.cart | json_decode %}     
    Your cart:
      • {% for item in cart %}
    • Item Name: {{ item.name }}

{% endfor %}

{% END_TWIG_BLOCK %}

This is how you can use TWIG blocks inside Aritic PinPoint Email Templates.



Still Not an User of Aritic PinPoint Automation?



Was This Article Helpful?

0 Comments

There are no comments yet

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.