Blueshift uses an open source templating language called Liquid for inserting dynamic content in messages.
You can use logical conditions and loops in your HTML templates to control the content that is sent to the customers.
Conditional tags must be wrapped in
{% %}.
Here are some examples of conditional logic. For more information, see the documentation for Liquid.
if statement
Example: Use an if statement to greet a customer as “Hi there” if the first name is not available for the customer.
Hi {% if user.firstname == blank %}there
{% else %}{{user.firstname | capitalize}}
{% endif %}!Example: Include a greeting in the customer’s preferred language. If the customer’s preferred language is not known or if the greeting is not available in the preferred language, use a specific language instead.
{% if user.locale == "fr" %}
Bonjour {{user.firstname}}! Partez pour un Voyage Fantastique!
{% elsif user.locale == "es" %}
Hola {{user.firstname}}! Embárcate en un viaje fantástico!
{% else %}
Hello {{user.firstname}}! Go on a Fantastic Voyage!
{% endif %}Example: Provide a discount offer based on customer tier or lifetime spend.
{% if user.lifetime_revenue 5000 %}
Here's a sweet 30% off coupon for you! Use code A30W23 when you check out.
{% elsif user.lifetime_revenue 1000 %}
Here's a sweet 20% off coupon for you! Use code B20W23 when you check out.
{% else %}
Here's a sweet 10% off coupon for you! Use code C10W23 when you check out.
{% endif %}Tip
When you compare the value of an attribute with an integer value, do not include double quotes.
For example,{% if user.extended_attributes.graduation_year == 2020 %}If you are comparing the value of an attribute with a string, include double quotes.
For example,{% if user.last_location_city == “New York” %}For push and inapp studio, complex liquid with double quotes may not work. Use single quotes interchangeably
For example,{% if user.last_location_city == ‘New York’ %}
for loop
You can use the for loop to display recommended products or to loop through attributes of a catalog item.
Example: Display all recommended items.
{% for product in recommendations.block1.products %}
{{ product.title }}
{% endfor %}Example: Display all recommended items sorted by the title.
{% assign sorted_products = recommendations.block1.products | sort: "title" %}
{% for product in sorted_products %}
{{ product.title }}
{% endfor %}Example: Display only 5 recommended items.
{% for product in recommendations.block1.products limit:5 %}
{{ product.title }}
{% endfor %}Example: Display all recommended items sorted by the title and display only 5
{% assign sorted_products = recommendations.block1.products | sort: "title" %}
{% for product in sorted_products limit: 5 %}
{{ product.title }}
{% endfor %}
case/when
You can use this switch statement to execute a particular block of code when a variable has a specified value.
Example: The same example of displaying text based on the users preferred language can be done using case/when.
{% assign language = {{user.language}} %}
{% case language %}
{% when "fr" %}
Bonjour {{user.firstname}}! Partez pour un Voyage Fantastique!
{% when "es" %}
Hola {{user.firstname}}! Embárcate en un viaje fantástico!
{% else %}
Hello {{user.firstname}}! Go on a Fantastic Voyage!
{% endcase %}
Conditional display of rows in Visual Studio
When you design an email or in-app template using Visual Studio, the Display Condition feature lets you define a custom condition for a row so that the row is displayed only to users who meet the specified criteria. In this way, you can use a single template to target multiple audiences. For example, you can use conditional display of rows to implement localization.
Use Liquid syntax and personalization attributes to define the condition.
Add the Liquid expression for the condition in the Before field.
Add
{% endif %}in the After field.
In the following example, a clothing sales promotion template contains promotions for both male and female customers.
The promotional content for female customers is in row 1 and the promotional content for male customers is in row 2.
Row 1 has the following display condition set: (condition =
{% if user.gender == "female" %}). As such this row is displayed only for female customers and not for male customers.Row 2 has the following display condition set: (condition =
{% if user.gender == "male" %}). As such this row is displayed only for male customers and not for female customers.
