Liquid Use Cases

Add unique URLs to pre-fill form details for existing customers

This approach offers a unique perspective on personalization, yet it has the potential to enhance customer convenience, minimize website obstacles, and ultimately deliver an improved customer experience.

Considering that you already possess your customers' data, why not take the initiative to simplify their interactions by automatically populating their information? It's a simple and highly effective method for streamlining the customer experience.

Let's take the example of a form accessible like the following example `

{% assign firstname = contact.firstname %}
{% assign lastname = contact.lastname %}

{% capture url %}{{ firstname }}&lastname={{ lastname }}
{% endcapture %}

{{ url }}


We use {% assign %} to extract the values of the contacts attributes firstname, lastname.
Next, we dynamically use {% capture %} to build the URL. Inside the capture block, we construct the URL string by concatenating the base URL ( with the parameters firstname, and lastname, each separated by &. The values of these parameters are obtained from the assignments made in the previous step.

Finally, we output the constructed URL using {{ url }}, displaying the full URL with the provided parameter values. You can customize the base URL and parameter names to suit your use case. You can encode url with url_encode filter.

Calculate a countdown from a set point in time

In this scenario, the use case computes the days between a designated date and the present day. This numerical disparity can then present a countdown to your users.

{% assign contractDate = contact.contractDate | date: "%s" %}
{% assign today = "now" | date: "%s" %}
{% assign difference = contractDate | minus: today %}
{% assign differenceInDays = difference | divided_by: 86400 | floor %}
you have {{ differenceInDays }} days left before your contract's renewal!

We use {% assign %} to extract the value of contractDate from the contact person, and we use the filter date with %s to convert the date into the number of seconds since 1/1/1970.
After we get the current time with the special word "now" and convert it to the number of seconds since 1st Jan 1970.
We compute the difference with the filter minus.
Then, we convert the number of seconds in days (dividing by 86400).
The filter floor is used to round down the number.

Localizing date

This use case will display the date in the contact's language.
Let's say we send a campaign triggered by an event containing an order date.

{{ | date: "%-d" }}
{% assign m = | date: "%-m" %}
{% if contact.language == "fr" %}
{% case m %}
{% when '1' %}Janvier
{% when '2' %}Février
{% when '3' %}Mаrs
{% when '4' %}Avril
{% when '5' %}Mаi
{% when '6' %}Juin
{% when '7' %}Juillet
{% when '8' %}Août
{% when '9' %}Septembre
{% when '10' %}Octobre
{% when '11' %}Novembre
{% when '12' %}Décembre
{% endcase %}
{% endif %}
{{ | date: "%Y" }}

We start by getting the day number without leading 0 by using the filter date: "%-d".
After we get the month number, we will display the month's name in French if the contact's language is fr

Localizing the from name when sending emails

This is done by using the following Liquid in your email’s ‘from name’ field:

Sophie {% case content.language %}
{% when 'fr' %} de ACME France
{% when 'nl' %} van ACME Belgium
{% else %} at ACME International
{% endcase %}