Description
The Setup block is a Liquid code block, which must not produce any direct output. Using the Setup code block of an element allows for data to be referenced anywhere in the element itself.
The Setup block can be found in the Email Designer, within any content element. Simply click the element and scroll down on the right hand navigation.
Pros:
- Good for saving Liquid in Saved Elements, making logic reusable
- Keeps liquid out of view & out of the copy
- Returned data is displayed in a dynamically generated grid
Cons:
- Logic placed here can only be referenced in the element and its child elements
- When testing campaigns, it can be difficult to pick out what Liquid may be causing unexpected results
- Calling for products via Liquid bypasses the de-duping that is built into dynamic grids, so there is risk for duplicate products to show up in campaign content if there is more than 1 dynamic grid
Steps
Using the Setup block of any element allows for data to be referenced anywhere in the element itself .
For this example we will use the liquid code: {{b_data[0].name}}
The Liquid code is used inside the Setup block of this specific Section content element.
‘b_data’ is referenced in the Text element that lives inside the Section element where the ‘b_data’ logic was set up.
Note: Variables are created as the template processes Liquid in the Variables section first, then the subject line and preheader, and then every text element in the email from top-to-bottom. If you want to use Liquid in your subject line, put your Liquid in the Variables section!
Using the Setup block for a dynamic grid
- Allows for data to be automatically iterated through and populate a dynamic grid
- Allows querying beyond what is available in dropdown menu (Details tab > Source)
- Allows for complex logic to be saved with the dynamic grid as a Saved Element
- Example:
Lookup ‘b_data’ is assigned in the Setup block of a dynamic grid:
'b_data’ is then referenced. In the Details tab of the dynamic grid, navigate to Content > Convert to Liquid.
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.