Advanced logic within emails

Movement renders all of your emails with Liquid, a templating engine which allows you to use advanced logic and conditions when building emails.

This guide explains how to use Liquid templating to create dynamic, personalised emails. With Liquid, you can insert data on your members, create conditional content, and generate dynamic lists based on your audience's information.

Merge tags

Merge tags can be inserted within any editor in the email builder, by clicking the 'Merge Tags' button, or the '+' icon.

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: {{ }}.

Built-in merge tags

Basic information

  • {{first_name}} - Person's first name (defaults to "Friend" if not set)
  • {{last_name}} - Person's last name
  • {{email}} - Person's email address
  • {{phone_number}} - Person's phone number
  • {{address_1}} - First line of address
  • {{address_2}} - Second line of address
  • {{address_3}} - Third line of address
  • {{address_4}} - Fourth line of address
  • {{postcode}} - Person's postcode

Membership details

  • {{joined_at}} - Date member joined
  • {{membership_status}} - Current membership status
  • {{external_id}} - Membership number

Organisation names

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'.

Custom fields

Any custom fields you've created in Audience -> Custom Fields are automatically available as merge tags. For example, if you have a custom field called "Constituency", you can use it as {{constituency}}. These will also be shown in the merge tag picker, for easy reference.

Conditional logic

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, and contains:

{% if membership_status == 'active' and joined_at < '2023-01-01' %}
  As a long-standing member...
{% endif %}

Loops and Collections

Liquid allows you to iterate over collections of data to create dynamic content.

Basic Loop Example

{% 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 %}

Best Practices

  1. Use fallbacks: Provide default content when merge tags might be empty:

    {{first_name|default: "Friend"}}
  2. Test your logic: Before sending, test your email with various several different records to ensure your conditional logic works as expected.

  3. Keep it simple: While Liquid is powerful, overly complex logic can be hard to maintain. Break complex operations into smaller, manageable pieces.

  4. 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-specific content here
    {% endif %}