Liquid Merge Tags

Sending personalized emails to your subscribers allows you to add a personal touch to your automated messages.

Encharge uses Liquid, a dynamic templating language built by Shopify. Liquid allows you to insert personalization in your emails, display dynamic content, and use data from people in your account in automation flows.

You can read below to get started, or check out the Liquid docs by Shopify.


Personalizing with people's data

To dynamically insert data into emails or flow steps, you can use the person object. For example, to dynamically insert the subscriber's first name in an email, you can use the following code: {{ person.firstName }} .

Personalization also works with custom fields. You can review all the fields in your account in Fields Management. To personalize with a custom field, use the field's "API Name" from Fields Management, like so {{person.field-api-name-here}}.

For example, the API Name for the "Last Name" field is lastName and the personalization tag would be {{person.lastName}}.


Insert the current date and time

You can insert the current date, formatted as simplified extended ISO 8601 format (e.g. 2020-12-30T19:35:54.019Z ) with the {% now %} Liquid tag.

This will generate the current date and time in the UTC timezone. If you want to add days/hours to that time you can use this trick.

Now, if you want to format this to be more user-friendly, for example "Hope you are having a wonderful Monday" you can use the following tag:

Hope you have a wonderful {% assign date = 'now' | date: '%s' %} {{ date | date: "%A"}}

If you need the time to be displayed in the Person's timezone, then you can use {{person.numberFieldName |in_timezone: person.timezone }}

you can also manually insert a timezone like this {{person.numberFieldName | in_timezone: "America/New_York" }}

Increase or decrease a number value

To increase the value of a number field use {{person.numberFieldName | plus: 1}} where "numberFieldName" is the name of the field and "1" is the number you'd like to add to the field's value.

To decrease it use {{person.numberFieldName | minus: 1}}.

Note that you can also use negative numbers.


Creating If/Else content 

A common practice is to personalize just a small part of your email content or even specific words. For that, you need to use Liquid's Control Flow.

Here's an example:

{% if person.subscription == "free-trial" %}

Upgrade your Encharge account today.

{% elsif person.subscription == "active" %}<br>

Create a Flow in Encharge.

{% else %}

Do you need help?

{% endif %}

This is what happens in the example above:

person.subscription is the attribute (i.e., merge tag) that we use to personalize the message.

  1. If a person's subscription is "free-trial" they will see this text: "Upgrade your Encharge account today."
  2. If a person's subscription is "active" they will see this text: "Create a Flow in Encharge."
  3. With any other values, i.e. when the person's subscription is neither "free-trial" nor "active", they will see: "Do you need help?"

Note that you might need to remove the extra spacing between lines. We've included them in the example above for easier readability.

Personalizing based on tags in Encharge

You can also create If/Else content based on whether a person has or doesn't have one or more tags in Encharge.

You can do this using the following liquid code:

{% if person.tags contains "customer" %}Happy to have you as a customer.{% endif %}

If the person has the tag customer, the following line will show to them "Happy to have you as a customer."


Replacing values

In some cases, you might want to replace a specific text value. Let's say you have a text number that is populated with a + sign (e.g., +123 123 123) but you want to only populate the numbers without the plus sign (e.g., 123 123 123).

To do that, you have to remove the plus sign with this code:

{{person.FieldName | replace:"+",""}}

Where the plus sign is replaced with nothing, i.e., it's removed.

To replace the plus sign with a different value, for example the country code +44, you'd use the following code:

{{person.FieldName | replace:"+","+44"}}


Advanced personalization

Encharge supports all Liquid tags and filters as described in the official Liquid docs.

Custom Liquid tags and filters in Encharge 

Encharge supports the following custom Liquid tags and filters:

now

Liquid Tag. Renders the current date and time in ISO 8601 format.

Example: 

The time is {% now %}

Output:

The time is 2021-11-30T15:53:18.019Z

titlecase

Liquid Filter. Formats the preceding text in Title Case.

Example: 

{{ "hello world" | titlecase }}

Output:

Hello World

random

Liquid Tag. Outputs a random number. There are 3 ways to use it:

1. Without arguments - outputs a random integer from 1 to 10.

Example: 

{% random %}

Output:

4

2. With 1 argument - outputs a random integer between 0 and the number passed.

Example: 

{% random 100 %}

Output:

42

3. With 2 argument - outputs a random integer between the passed numbers.

Example: 

{% random 100 1000 %}

Output:

837

set_timezone

Liquid Filter. Changes the timezone of the provided date.

Example: 

{{ "2013-02-08T09:30:26.000Z" | in_timezone: "America/Los_Angeles" |}

Output:

2013-02-08 01:30:26 -08:00

in_timezone

Liquid Filter. Converts the provided date and time to the specified timezone.

The difference between  in_timezone and set_timezone is that in_timezone modified both the time and the timezone, keeping the modified date and time pointing to the same moment in time.

See supported timezones (TZ database name column).

Example: 

{{ "2013-02-08T09:30:26.000Z" | in_timezone: "America/Los_Angeles" |}

Output:

2013-02-08 01:30:26 -08:00

set_timezone

Liquid Filter. Converts the provided date to the same local time in the specified timezone. 

The difference between in_timezone and set_timezone is that with set_timezone only the timezone is updated, keeping the local time the same. Consequently, the modified date and time will now point to a different moment in time.

See supported timezones (TZ database name column).

Example: 

{{ "2013-02-08T09:30:26.000Z" | set_timezone: "America/Los_Angeles" }}

Output:

2013-02-08 09:30:26 -08:00

fetch_json

Liquid Tag. A powerful advanced tag that can contact your API to bring any dynamic data in your Encharge emails. 

This tag retrieves JSON data and makes it available for you to use in subsequent Liquid tags and filters.

This tag doesn't print anything.

Usage:

{% fetch_json method variableName = endpointURL %}

This will fetch the data from endpointURL using method (e.g. POST or GET, will use GET if omitted), and store it in the variableName for subsequent usage. See the following example.

Example:

Let's say that you have an API endpoint https://mock.api/v1/user/123 that returns the following data:

{
  "user": {
    "plan": "premium",
    "name": "John"
  }
}

Then you can use the fetch_json tag like this: 

{% fetch_json userData = https://mock.api/v1/user/{{person.customUserId}} %}` 
Hello {{ userData.user.name }},
Your plan is {{userData.user.plan}}
... rest of email follows ...

Which will output

Hello John,
Your plan is premium
... rest of email follows ...

fetch_html

Liquid Tag. Typically used in emails, it retrieves an HTML snipped from a page that you specify and inserts it into the email verbatim.

Example: 

{% fetch_html https://example.com/test %}`

Output:

<html><head>
    <title>Example Domain</title>
</head>
<body>
<div>
    <h1>Example Domain</h1>
</div>
</body></html><br>

You can also specify the method to use like so: {% fetch_html POST https://example.com/test %}`. If omitted GET will be used by default.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.