Twig Templates
Snippets Library

High level of personalization for your e-mails, landing pages and text messages using Twig syntax.     

{% if contact.companies is defined and contact.companies is not empty %}
    {% for company in contact.companies %}
        {% if company.is_primary == '1' %}
            <p>Primary Company: {{ company.companyname }}</p>
            <p>Custom Field: {{ company.companycustomfield }}</p>
            {% break %}
        {% endif %}
    {% endfor %}
{% else %}
    <p>No companies associated.</p>
{% endif %}

Contact’s companies and company custom field

{% for tag in contact.tags %}
        {{ tag }}      
 {% endfor %}

Contact’s tags

{% for segment in contact.segments %}        
        {{ segment.name }}
 {% endfor %}

Contact’s segments

{% set content = 'https://your.url' | get_content_from_url | json_decode %}
{{ content.title }}
{{ content.data }}
{{ content.link}}

Get the content from an external URL address, decode it and process it as array

Example usage for abandoned cart content
{% if contact.affinity == 'private' %}
<p>This is Private Content</p>
{% endif %} 
{% if contact.affinity == 'b2b' %}
<p>This is B2B Content</p>
{% endif %} 
{% if contact.affinity == 'agency' %}
<p>This is Agency Content</p>
{% endif %}

Content Segmentation based on Contact Affinity

Basic example for displaying content based on a contact field value, in this case, depending on your contact's affinity.
{{ contact.firstname|capitalize }}

Always capitalize

{% set feed= 'https://your.rss.feed.url' | rss %}

<h1>{{ feed.channel.title }}</h1>
<p><a href="{{ feed.channel.link }}">{{ feed.channel.link }}</a></p>
<p>Published: {{ feed.channel.pubDate }}</p>
<p>{{ feed.channel.description }}</p>

<h2>Articles</h2>
<ul>
    {% for item in feed.channel.item %}
        <li>
            <h3><a href="{{ item.link }}">{{ item.title }}</a></h3>
            <p>Published: {{ item.pubDate }}</p>
            <div>{{ item.description|raw }}</div>
        </li>
    {% endfor %}
</ul>

Fetch RSS data

{% set dateExpiry = contact.date_last_order |date('d-m-Y') %}
{% set today = "now"|date('d-m-Y') %}
{% set difference = date(today).diff(date(dateExpiry))%}
{% set leftDays = difference.days %}
{% if dateExpiry == today %}
      1 day
{% else %}
    {{ leftDays }} days left
{% endif %}

Expiry date

{% set currentTime = "now"|date("H") %}
{% if currentTime >= 5 and currentTime < 12 %}
    <p>Good morning!</p>
{% elseif currentTime >= 12 and currentTime < 18 %}
    <p>Good afternoon!</p>
{% else %}
    <p>Good evening!</p>
{% endif %}

Time-based greetings

<p>The Gender is {{contact.gender|default('unknown')}}</p>

Fallback

Tomorrow
{{ "now"|date_modify('+1 day')|date("m/d/Y") }}

Today
{{ "now"|date("m/d/Y") }}

Today is happy {{ "now"|date("l") }}

Magic with dates

{{ random(['apple', 'orange', 'citrus']) }}

Random

{% if contact.title %}
  {% if contact.title == "Frau" %}
	<p>Sehr geehrte {{contact.title}} {{contact.lastname}}</p>
  {% endif %}
  
  {% if contact.title == "Herr" %}
   <p>Sehr geehrter {{contact.title}} {{contact.lastname}}</p>
  {% endif %}
{% endif %}

Gender-based proper greeting (German example)

{% set cart = contact.json_field | json_decode %}
{% for item in cart %}
{{item.name | raw }}
{% endfor %} (edited)

Personalize content (cart, orders.,..) with JSON decode

Set JSON to the contact field and then process it during the build content. Useful for contact's personalized content like cart or order.
{{ tokens['{mycustomtoken}'] }}

Support for email tokens in API

To send an email through an API, you'll need to pass tokens and include the content in the email. This can be done by utilizing JSON decode functions.
Built on Unicorn Platform