Adding dynamic content to emails using display conditions
Overview
Dynamic email content allows you to personalize emails by showing recipients only the information and visuals relevant to them.
This is done by setting display conditions that show or hide content based on a recipient's activity, attributes, or field values.
You can easily create display conditions using a condition builder, or if you feel comfortable, you can write them in Liquid language yourself.
Create display conditions using the condition builder
An easy way to create dynamic content is by applying display conditions to a row in an email message. This allows you to control the visibility for large sections of content using only one display condition.
To add a display condition for a row:
- Click on the row you want to manage, then at Rows > Row properties > Dynamic content, click Open builder.
2. When you click on Open builder, you’ll see the New condition modal.
3. Give your condition a Name and a Description.
4. At Filter, set the conditions you want recipients to meet to be able to view the content.
NOTE: The conditions added will be automatically generated as Liquid language, which is what determines the content that recipients see..
Learn more about Liquid and how to write your own conditions using Liquid.
NOTE: Currently, the condition builder only allows you to select person and organization fields. To create conditions based on activity attributes, you will need to write the conditions in Liquid yourself.
About display conditions and Liquid
Display conditions use Liquid language and merge tags to determine what recipients see.
When creating email messages, you have the option to use the condition builder which will automatically generate Liquid conditions for you. Or if you feel comfortable, you can write your own conditions in Liquid.
If you want to learn more about Liquid, we recommend reading our guides on:
- Liquid syntax, including operators
- Control flow tags (such as if statements), and
Create display conditions by writing in Liquid
You create display conditions for rows at the Content step when creating an email message:
- Click on the row you want to manage, then at Rows > Row properties > Dynamic content, click Add Condition.
2. In the Add a new display condition modal, give your condition a Name and a Description.
3. Add your beginning and ending conditions to the respective Before and After fields.
NOTE: The Before and After fields need to include control flow tags (e.g. if, else) to work correctly.
EX: If we want to display content only to people who are subscribed to a Gold level plan, using a custom field called Plan tier, the liquid would be formatted as follows:
{% if people.custom.plan-tier == “Gold” %} {% endif %}
4. Click Confirm to save the condition.
Alternatively, you can write Liquid conditions in the condition builder:
- At Rows > Row properties > Dynamic content, click on Open builder. Then in the New condition modal, click Write as Liquid to access the Liquid input fields.
2. Add your beginning and ending conditions to the respective Before and After fields.
3. When you’re ready, click Save.
View and edit a display condition
When you’ve saved a display condition, you can view it at Rows > Row properties > Dynamic content.
Click the down arrow (⌄) on the condition to view the raw Liquid syntax.
To make changes to the condition:
- For the condition builder: Click Open builder. This will open the New condition modal in which you can make changes to the filter, then click Save to save the changes.
- For raw Liquid: Click Edit condition. This will open the Edit display condition modal in which you can make changes to the Liquid syntax, then click Confirm to save the changes.
To delete a row’s display condition, click the X.
Reuse display conditions
While display conditions are not saved at an account level (i.e. you cannot access conditions created in Email A when drafting Email B), there are a few ways you can reuse or access existing display conditions.
Duplicate a row in the same email
If you have an email that contains multiple separate rows that need the same display conditions, you can create the condition on one row, then duplicate it. The duplicated row will include the display condition from the original row, and you can then edit the row’s content as required.
Create a saved row
If you save a row containing a display condition, the display condition will be included when the saved row is used in future. So if you save a row in Email A, when you draft Email B you can add the saved row from Email A (which contains content and display conditions). Learn more about saved rows.
Duplicate the email containing display conditions
Use an existing email containing display conditions as a template by duplicating it to access the existing content and conditions.
Preview display conditions
To see how your content will look to the recipient, you can click Preview at the Content step, or view the preview at the Review step.
When previewing your email, you can see how merge tag values and rows with display conditions will be displayed by clicking the person icon > Random recipient. If the random recipient has values for the fields and attributes contained in the merge tags and row conditions, the preview will show you that person’s field values in the email content, plus any rows they are eligible to view. Otherwise, the content will show the fallback values, or will be blank or missing if no fallbacks are present.
You can also use the same menu to preview the raw Liquid code, and the merge tag fallbacks you have set.
Other ways to add display conditions
Instead of (or in addition to) adding display conditions to rows, you can also create dynamic content by writing Liquid display conditions in text boxes to control the visibility of text, images, or other elements.
You can either add the full condition to one text box, like this example which displays different text based on a person’s language field value:
{% if people.language == ‘en-us’ %} Hello {{ people.first-name }} {% elsif people.language == ‘es’ %} Hola {{ people.first-name }} {% endif %}
Or, you can spread the condition across multiple text boxes in the same row to surround and control other content. In the example below, the condition described above is split over 2 text boxes to display different text to people based on their language field value:
Use cases and tips
Because you can create display conditions based on system, custom, and data source activity attributes and fields, there are plenty of opportunities to customize and personalize your email message content.
Here are some examples of display conditions you can create to suit a variety of use cases.
Additional examples for creating conditions in Liquid are available in the articles under Using Liquid language.
Activity attributes
Example | Liquid |
---|---|
Show content to people who clicked a specific URL in a specific email |
|
Show content to people who recently viewed a product that you are trying to promote |
|
Show content to people depending on how many times they performed a particular activity |
|
Field values
Example | Liquid |
---|---|
Show content to customers who spent or donated a particular amount:
|
NOTE: We store currency or floating point number field values as the original number multiplied by 1000 (so it can be rendered as a decimal number). So in the above example, |
Show content to members of a specific audience |
To get the <audience ID>, you will need to view that audience in Ortto and copy the audience ID from the URL, like so: In the Liquid it will look like:
|
Show a custom footer or signature row for each of your team members |
|
Show content to people who fit a particular age bracket |
|
Show content to organization owners depending on on the organization size |
|
Show content to people who expressed interest in learning more about a speciality of yours or a service you offer |
|
Multi-language content
If you are creating an email message for subscribers in different languages, you can set row conditions to ensure that a person only sees the content associated with their preferred language.
When creating a display condition, you can use the filter condition People > Language is <x> or write in Liquid as {% if people.language == ‘<x>’ %} {% endif %}
Then, in the row, you type text in the relevant language, and add images and other elements as required.
Learn more about displaying translated email message content.
Dynamic content from a JSON object
If you are using a JSON object to populate your email content, you can set display conditions to loop through a number of items in the object. For example, you are sending an email to a customer who has started a checkout on your website. You can use a display condition to access the “checkout started products” activity attribute which is a JSON object containing the order details.
In the email content row, you can then use merge tags to output the object values.
A full description of this example is available in Accessing JSON objects with Liquid.
You may also like to learn more display conditions when using a JSON endpoint for dynamic email content.