Liquid Formatting
Personalised data in communications from Movement
Across the Movement app, The Liquid templating language is available to customise and personalise content and messages. Most commonly Liquid is used to personalise email and text message communication as well as pages and thank you emails.
With Liquid, you can insert data on your members, create conditional content, and generate dynamic lists based on your audience's information.
Typically this is done through the use of merge tags, for instance Hi {{ first_name }}, would insert the recipients first name into the message: Hi Bob,. More complex customisation is available through the use of advanced logic tags and filters.
Depending on the context, different variables are available for templating. Merge tags can be inserted within editors by clicking the 'Merge Tags' button, or the '+' icon. These tag variables can additionally be used within more advanced logic tags and filters.
Merge Tags
Merge tags, also known as objects in Liquid parlance, provide a way to substitute custom data into text. These allow you to dynamically insert member data into your emails, whether it's within paragraphs, links, buttons, or anywhere else. Merge tags are always wrapped in double curly braces: {{ }}.
When dealing with contexts that have member data, there is access to variables such as:
Basic Information
first_name: First name of the memberlast_name: Last name of the memberemail: Email of the memberphone_number: Phone number of the memberaddress_1: Address line 1 of the memberaddress_2: Address line 2 of the memberaddress_3: Address line 3 of the memberaddress_4: Address line 4 of the memberpostcode: Postcode of the member
Membership
join_date: Date the member joinedmembership_status: Status of the members membershipexternal_id: Membership number
Custom Fields
Custom fields can be utilised through the 'API name' of the custom field, which can be viewed from the Custom Fields setup screen within Audiences.
For example, if you have a custom field called "Parliamentary Constituency" and an API name of constituency, you can use it as {{ constituency }}. These will also be shown in the merge tag picker, for easy reference.
Organisations
Movement creates a merge tag for each organisation type you have. For example, if you have Regions, Councils, and Towns, you may have the following merge tags:
{{ organisations.region }},{{ organisations.council }},{{ organisations.town }}
You can find these in the merge tag picker, by clicking 'Organisations'.
Additional Contextual Data
In certain circumstances there may be additional data available such as public share links to the page the member is on, recent actions, donation history, and more.
Alternate Contexts
In some contexts such as page thank you emails, there won't be a valid member and so only a subset of typical merge tags may be available. Use the merge tag selector to view the available variables.
Conditional Logic
The same variables used for merge tags can also be used within logic tags. Logic tags are differentiated from merge tags through the delimiters {% and %} instead of {{ and }}.
You can show or hide content based on merge tag values using Liquid's if, elsif, and else statements.
Basic Conditionals
{% if first_name != blank %}
Dear {{first_name}},
{% else %}
Dear Friend,
{% endif %}Multiple Conditions
{% if membership_status == 'active' %}
Thank you for being a valued member!
{% elsif membership_status == 'pending' %}
Please complete your membership registration.
{% else %}
Join us today to unlock exclusive benefits!
{% endif %}Complex Conditions
You can use operators like and, or:
{% if membership_status == 'active' and joined_at < '2023-01-01' %}
As a long-standing member...
{% endif %}Examples
Based on the region of the member. To retrieve the name of the variable, use the merge tag picker.
{% if organisations.local_region == 'London' %}
Lives in London!
{% else %}
Elsewhere
{% endif %}Based on a custom field. Here a custom field representing the next event id the member has rsvped to. If blank then they have no upcoming events.
{% if soonest_rsvp_event_id == blank %}
No event
{% else %}
Has event
{% endif %}Filters
Filters are used to modify the output of a Liquid variable.
Defaults
If a variable is not present, the default value will be used,
{{ first_name | default: "Friend" }}For a user with a first_name set will display that, otherwise will display Friend
Multiple Filters
{{ organisation.region | capitalize | prepend: "Welcome to " }}For a member who is a member of the organisation region hartlepool, will display Welcome to Hartlepool
Loops and Lists
Liquid allows you to iterate over lists of data to create dynamic content.
Assigning values
You can assign values to new variables using the assign tag:
{% assign fruits = "apples, oranges, peaches" | split: ", " %}Assigns the new variable fruits to a list of items apples, oranges, and peaches.
The collection was created by splitting apples, oranges, peaches, between , .
Looping
Loop through variable using for syntax:
{% for fruit in fruits %}
- {{ fruit }}
{% endfor %}Will display an item for each fruit:
- apples
- oranges
- peaches
Address Loop Example
This will show the 4 lines of an address if present
{% if address_1 != blank %}
Your registered addresses:
{% for i in (1..4) %}
{% assign address_field = 'address_' | append: i %}
{% if address_field != blank %}
{{address_field}}
{% endif %}
{% endfor %}
{% endif %}Comments
You can disable processing and rendering of code by using comment tags. You may use these to explain how logic works or temporarily disable functionality.
{% comment %}
This won't be visible!
{{ nor_this_variable }}
{% endcomment %}Best Practices
- Use fallbacks: Provide default content when merge tags might be empty:
{{first_name|default: "Friend"}}-
Test your logic: Before sending, test your email with various several different records to ensure your conditional logic works as expected.
-
Keep it simple: While Liquid is powerful, overly complex logic can be hard to maintain. Break complex operations into smaller, manageable pieces.
-
Check for empty values: Always verify that data exists before trying to use it in complex operations:
{% if postcode != blank and postcode contains "SW" %}
London-south-west-specific content here
{% endif %}Further Reading
Many other tags and filters are available. You can learn more about Liquid and these at the Shopify Liquid docs.
You can read more about Donation data in emails.
Updated 2 months ago
