Liquid is an open-source template language that enables advanced email personalization far beyond basic techniques like name insertion. By incorporating sophisticated conditional logic and data manipulation, it allows you to create dynamic email content that automatically adapts to each subscriber's unique data and preferences, whether based on contact information, purchase history, or custom field values.
The result is a more professional and engaging email experience that maintains brand consistency while delivering highly relevant, personalized messages at scale.
This level of personalization significantly enhances subscriber interaction and drives better campaign results by ensuring that each contact receives content tailored specifically to them. Rather than sending one-size-fits-all emails, Liquid scripting empowers you to scale individualized communication across your entire email marketing program, making it a powerful tool for improving both engagement and overall campaign performance.
Marketing Cloud uses Liquid scripting to dynamically display email content containing data from standard and custom fields, Dynamic Content Blocks, Relational tables, Content Feeds, and Transactional messages.
Liquid Filters
String Manipulation
Liquid scripting enables the use of filters that manipulate data and change the form it takes. Filters can be used to personalize the subject lines as well as the email content. Filters are denoted by the pipe character "|" and are placed within an output tag "{{}}."
A good example of a liquid filter is capitalizing the end user’s name:
INPUT:
{{contact.first_name | capitalize}}
OUTPUT: Ben
And, to lowercase a name:
INPUT:
{{contact.first_name | downcase}}
OUTPUT: ben
Date/Time Formatting
Another great example is the date filter. It converts the time stamp into another data format:
INPUT:
{{other.time_stamp | “%a, %b, %d, %y”}}
OUTPUT: 26 October 2016
Note: The format for this syntax is the same as strftime.
Cryptographic Hashing
The MD5 hash is a cryptographic function that converts a piece of data, such as an email address, into a 32-character hexadecimal string.
INPUT:
{{contact.email | md5}}
OUTPUT: 20332b7bb9fb981a16346092956278e1
This filter is particularly helpful for those looking to include personalized advertising within emails. The unique 32-character string enables third-party advertising services to build profiles on recipients as emails are opened and display ads are clicked, without any actual exchange of email addresses taking place.
Conditional Logic
Both Liquid Script and Dynamic Content Blocks support IF/THEN/ELSE conditional logic for displaying personalized email content, giving you two approaches to achieve similar outcomes. The right choice between them largely depends on the complexity of your rules and the content you intend to display.
Liquid script is best suited for straightforward scenarios where the conditional rules are based solely on standard or custom field values and the content to be displayed is relatively simple. Dynamic content blocks, on the other hand, are better equipped to handle situations where both the conditional rules and the content itself are more complex in nature.
Default Display for First/Last Name
An IF/THEN/ELSE conditional statement is helpful to display a default first name or last name when none exists for any given contact.
Hello {% if contact.first_name == blank %} valued member {% else %} {{contact.first_name | capitalize}} {% endif %}
Note: You can use the Liquid keyword blank to test whether a standard field is empty or not for any given contact.
Default Display for Custom Fields
Unlike standard fields, which exist for all contacts regardless of whether they contain a value or not, Marketing Cloud only stores custom fields for contacts that actually have a value assigned to them. This fundamental difference in how the two field types are stored means that applying conditional logic to custom fields requires a slightly different approach.
Rather than simply checking whether a custom field contains a value, the condition must first determine whether the custom field exists for a given contact at all. In other words, the absence of a custom field for a contact is itself meaningful, and any conditional logic applied must account for this by testing for the field's existence before evaluating its value.
Your balance is {% if contact.points %} {{contact.points}} {% else %} 0 {% endif %} points