Tags are the programming logic that tell Liquid what to do. They are generally used in pairs of opening and closing tags. The opening tag will specify the logic statement to be evaluated. The desired output, based on the conditions evaluated, is specified between the opening and closing tags. The end tag simply ends the logic statement. Tags are never visible as output.
Tags are formatted as follows: {% tag name %}
Tag Operators
Tag operators are used to create the logic statement within a tag.
==
is equal to!=
is not equal to<
is less than<=
is less than or equal to>
is greater than>=
is greater than or equal toand
checks that both condition A and condition B existor
checks that either condition A or condition B existcontains
checks for a substring within a string or an array
and
, or
, and contains
operators are case sensitive. Use lowercase letters only.
Control Flow Tags
The following tags allow you to define conditions that determine whether a block of Liquid is executed and as such, which values are displayed in an email or other fields within Drip.
if
Used to insert if/then logic into an email.
Input
{% if subscriber.membership_level == "Gold" %} Congratulations on reaching Gold level membership! {% endif %}
Output
Congratulations on reaching Gold level membership!
unless
Essentially the opposite of the {% if %}
tag. This tag executes a block of code only if a set of conditions are NOT met (that is if the result is false).
Input
{% unless subscriber.tags contains “customer” %} Your trial has ended. Buy an annual subscription today! {% endunless %}
Output
Your trial has ended. Buy an annual subscription today!
else/elsif
Used with the {% if %}
or {% unless %}
tags to evaluate multiple conditions. Only the first matching condition will execute.
Input
{% if subscriber.destination_state == "Florida" %} Don’t forget to bring your sunscreen! {% elsif subscriber.destination_state == "Alaska" %} Don’t forget to pack a jacket! {% else %} Have a great trip! {% endif %}
Output
<!-- subscriber.destination_state is "Florida" --> Don’t forget to bring your sunscreen! <!-- subscriber.destination_state is "Alaska" --> Don’t forget to pack a jacket! <!-- subscriber.destination_state is something else or not set --> Have a great trip!
case/when
Used to determine copy output based on multiple possible object values. The {% case %}
statement identifies the object to be evaluated and the {% when %}
statements define the possible conditions.
You can optionally add a {% else %}
tag at the end of the case to provide copy to output if none of the conditions are met.
Input
{% case subscriber.buyer_type %} {% when "basic" %} Thanks for becoming a basic member. {% when "gold" %} Congrats on becoming a Gold member. {% when "platinum" %} Awesome! You’re a Platinum member. {% else %} Thanks for checking us out! {% endcase %}
Output
<!-- subscriber.buyer_type is "basic" --> Thanks for becoming a basic member. <!-- subscriber.buyer_type is "gold" --> Congrats on becoming a Gold member. <!-- subscriber.buyer_type is "platinum" --> Awesome! You’re a Platinum member. <!-- subscriber.buyer_type is something else or not set --> Thanks for checking us out!
Variable Tags
The following tags are used to set variables that can then be used throughout an email, template, workflow, or rule.
assign
Creates a named variable and stores it in memory. This tag uses no closing tag. To output the variable, simply call it within double curly braces: {{}}. You can optionally use filters as part of the assignment.
Input
{% assign order_total = purchase.value %} {% assign discount_amount = 5 %} {% assign discounted_total = order_total | minus: discounted_amount %} Thanks for your order! Your subtotal was ${{ order_total }}, but your discount of ${{ discount_amount}} brings your total down to ${{ discounted_total }}.
Output
<!-- purchase.value was 45 --> Thanks for your order! Your subtotal was $45, but your discount of $5 brings your total down to $40.
capture
Captures the string inside the opening and closing tags and stores it to a named variable. All variables created with a capture tag are stored as strings.
Use a capture tag instead of an assign tag when you want to capture multiple lines of text or preserve other HTML formatting.
To output the capture variable, simply call it within double curly braces: {{}}. Additionally, you can use filters as part of the assignment.
Input
{% capture facebook_cta %} Don't forget! We're also on Facebook! {% endcapture %} .. {{ facebook_cta }}
Output
<!-- actual HTML stored in memory --> <strong>Don't forget!</strong> We're also on <a href="https://www.facebook.com/Leadpages">Facebook</a>! <!-- rendered HTML in email --> Don't forget! We're also on Facebook!
Other Tags
The following tags allow for miscellaneous functionality within Drip.
comment
Creates a comment separate from other output text. Text within comment tags is never outputted.
Input
{% comment %} This section of the email offers an upsell {% endcomment %} Buy ABC product today and get XYZ product for half off!
Output
Buy ABC product today and get XYZ product for half off!