Dynamic merge tags are more powerful and flexible than you may realize. Here we will walk through how to use advanced and conditional merge tags to include dynamic content that takes your email presentation to the next level.
Displaying the user's first name
Price Drop stage: Displaying percent off (for custom implentations)
Displaying the user's first name
The First Name merge tag is the most popular choice for dynamic text within the subject line or body of an email. An if statement is used to control the content displayed - if the first name is available it is used, otherwise alternate text is used.
The default first name merge tag looks like this:
{% if fname == null or fname == '' %} Section 1 {% else %} Section 2 {% endif %} |
Section 1: The text in Section 1 will only be displayed in the case where there is no first name value for the given user.
Section 2: The text in Section 2 will only be displayed in the case where there is a first name value for the given user.
Important! Spaces are not automatically included with the merge tags and usually need to be added to either the first name content or at the beginning of the static content. Keep an eye on your spacing when building your tags and use the examples listed here as a reference!
So how can we use this knowledge to make better subject lines and emails? Let's take a look at a few examples:
Example 1: Cart Abandon Stage
Let's suppose we wanted the following subject line outputs:
You forgot something! |
and
Hi {{fname}}, you forgot something! |
How would we update the outline below to output these desired subject lines?
{% if fname == null or fname == '' %} Section 1 {% else %} Section 2 {% endif %} |
Section 1: In the case where there is no available first name to display, the desired output is "You forgot something!". Therefore, the value for Section 1 is, "You forgot something!".
Section 2: In the case where there is an available first name to display, the desired output is "Hi {{fname}}, you forgot something!". Therefore, the value for Section 2 is, "Hi {{fname}}, you forgot something!".
Entering these values into the outline above gives us the complete subject line:
{% if fname == null or fname == '' %} You forgot something!{% else %} Hi {{fname}}, you forgot something {% endif %} |
Tip: Avoid using "friend" or "Dear sir" as your default greeting. These two are the most likely to flag your message as spam!
Example 2: Welcome Stage
Let's suppose we wanted to welcome users who visited your store with the following subject lines:
We're so glad you visited our store! |
and
{{fname}}, thanks for visiting our store! |
How would we update the outline below to output these desired subject lines?
{% if fname == null or fname == '' %} Section 1 {% else %} Section 2 {% endif %} |
Section 1: In the case where there is no available first name to display, the desired output is "We're so glad you visited our store!". Therefore, the value for Section 1 is, "We're so glad you visited our store!".
Section 2: In the case where there is an available first name to display, the desired output is "{{fname, thanks for visiting our store!". Therefore, the value for Section 2 is,"{{fname, thanks for visiting our store!".
Entering these values into the outline above gives us the complete subject line:
{% if fname == null or fname == '' %}We're so glad you visited our store!{% else %}{{fname}}, thanks for visiting our store!{% endif %} |
Advanced liquid functions
Cortex merge tags are inserted using liquid code, and their values can be treated as strings, and modified using Liquid String Filters.
Example 1: Standardize first name capitalization
If a user submits BRITTANY, or brittany, we want to output "Brittany".
Instead of showing {{fname}}, we are going to lowercase, then capitalize the first letter.
{{ fname | lowercase | capitalize }}
This can of course be used in combination with the conditional display statement for fname.
{% if fname == null or fname == '' %}We're so glad you visited{% else %}{{ fname | lowercase | capitalize }}, thanks for visiting{% endif %} our store! |
Example 2: Limit length of item description
{{ rs_rpd1 | truncatewords: 20, "read more..." }} |
The Date Function merge tag
Sometimes you need to use dynamically populated dates in your emails; the most popular use case is coupon code expiration dates. For this we have the "now" and "days from now" merge tags.
The basic structure looks like this:
{{ 0 | days_from_now | date: "%B %d, %Y" }} |
or
{{ 7 | days_from_now | date: "%B %d, %Y" }} |
which outputs in the format:
March 01, 2018 |
By changing the first number in the "days from now" control, it's possible to reflect past and future dates dynamically.
We can also change the printed date format by substituting different variables in the date section.
You can learn about all the different ways to display dates here. Some examples are displayed below:
Date Structure | Output |
"%B %d, %Y" | March 01, 2017 |
"%A, %B %d, %Y" | Wednesday, March 01, 2017 |
"%x" | 03/01/17 |
"%a, %B %d" | Wed, March 01 |
"%A, %x" | Wednesday, 03/01/17 |
Price Drop stage: Displaying percent off (Only works on custom implementations)
Example: Price Drop email, show original price, new price that has dropped + percentage off.
What you need:
- Items file to include original price and dropped price.
- The below code in the HTML of the email.
Here is what the email looks like in the HTML template builder:
Here is what the email looks like in the inbox:
Want to learn more? ReSci merge tags are made with Liquid for web-based programming. Learn more about liquid code here. |
Comments
0 comments
Please sign in to leave a comment.