Description
This will show some basic functionality when it comes to using the syntax for Liquid coding.
Steps
When using liquid code directly in the Email Designed (content, URL, Subject) - if you are adding raw code simply enclose the Liquid code statement in a double curly brace {{ }}
- All logic is enclosed with “{%” and “%}”
- Use double curly braces to display what you assign: {{ and }}
- Example: For use with coupon codes;
In panel A ‘amt1’ is assigned the value ‘$10 OFF $100’.
In panel B, ‘amt1’ is being referenced. When the campaign is previewed or sent out, ‘{{ amt1 }}’ will show the value it was assigned.
A.
B.
Variable assignment
-
- {% assign myVar = ‘hello there’ %}
- {{myVar}} in the Email Designer will print “hello there”
-
Conditional statements
- {% assign myVar = ‘hello’ %}
- {% assign a = 2 %}
- {% if a > 2 %}
- {% assign myVar = ‘goodbye’ %}
- {% endif %}
- {{myVar}} will print “hello”
-
Logical and Comparative Operators
- Documentation on Liquid Operators are found here: https://help.shopify.com/en/themes/liquid/basics/operators
-
Caveats in ODP
-
In lookups, you must use ‘=~’ or ‘!=~’ with wildcards (*)to designate matching/not matching
- Everywhere else, including Setup blocks, Conditions, and Variable sections, you can use ‘contains’ to find a matching value
- Note: there is no ‘does not contain’ operator in Liquid
-
Money is not supported in Zaius, use this to format numbers to have two decimal points
- {%if product.price != blank %}${{'%0.2f' | format: product.price }}{% else %}{% endif %}
-
In lookups, you must use ‘=~’ or ‘!=~’ with wildcards (*)to designate matching/not matching
Additional Resources
- Liquid is “an open source template language created by Shopify”
- “Open source”: Engineers can make changes to it and adapt it for their own needs -- we did this
- “Template language”: A nice way to put data on an email/page
- Sources of public documentation:
- Shopify’s: https://help.shopify.com/en/themes/liquid
- Ours: https://support.optimizely.com/hc/en-us/articles/4407775274253-Personalize-with-optional-content
- Ours: https://support.optimizely.com/hc/en-us/articles/4407775333261-Advanced-Liquid-capabilities-in-ODP
- Shopify also has a Github repo for local testing: https://shopify.github.io/liquid/
Please sign in to leave a comment.