Liquid syntax feature in the mail
Topics covered:
-
About:
-
The Filters that support Liquid Syntax
-
Formatting statements
-
If/Else Statement
-
Case Statement:
-
Operators
-
Understanding Liquid Syntax with Examples
About
Liquid syntax is a template language. Cadence offers the choice of selecting the right data and organizing your emails using the Liquid template language. You can personalize your email using this.
The Filters that support Liquid Syntax
The filters that are supported are append, capitalize, escape, upcase, split,remove_first, etc;
Formatting statements
Let's look at some examples of formatting statements
The liquid syntax allows you to easily format dynamic fields.
Examples:
First Name: {{first_name}}
First Name: {{first_name | upcase }}
First Name: {{first_name | downcase }}
If/Else Statement
Liquid syntax allows you to add logic to your template. To support several scenarios for use with a single template, you can utilize tags to execute if/else statements.
Example:
A typical if/else statement can be written as:
{% if first_name %}
Hi {{first_name}},
{% else %}
Hello,
{% endif %}
Case Statement
If you need more conditions, then an if/else statement might not be the best option. In that case, you can use the case statement.
Example:
A typical case statement can be written as follows:
{% case country %}
{% when 'France' %}
Bonjour #{{first_name}},
{% when 'Spain' %}
Hola #{{first_name}},
{% else %}
Hi #{{first_name}},
{% endcase %}
Operators
In conditional statements, you have logical operators available to use.
Example:
The operators available are:
== equals
!= does not equal
> greater than
< less than
>= greater than or equal to
<= less than or equal to
Understanding Liquid Syntax with Examples
You can use the variable that holds the company's website or the email address of any particular person in Cadence's liquid syntax. The syntax can be used to organize your emails, including the else-if sentence.
Example:
{% if website != blank and email != blank %}
{{ company_name | capitalize }} has a website at {{ website }}. Feel free to check it out!
{% elsif website != blank %}
{{ company_name | capitalize }} has a website at {{ website }}.
{% elsif email != blank %}
You can contact {{ company_name | capitalize }} via email at {{ email }}.
{% else %}
No contact details available for {{ company_name | capitalize }}.
{% endif %}
Note: To see more liquid syntax examples, view the Source documentation, maintained by Shopify.