AI Content Decisioning Agent lets you test multiple versions of your message content and automatically delivers more of what performs best.
This guide will walk you through how to write content variations with the vary() function and add them to your email, SMS, and push templates.
How to Set Up Content Variations
Write Your Variation Code
Define each variant using capture, then pass them to vary():
{%- capture SL1 -%}Your weekend offer is here{%- endcapture -%}
{%- capture SL2 -%}Don't miss your Friday bonus{%- endcapture -%}
{%- capture SL3 -%}Exclusive: this week only{%- endcapture -%}
{{ vary([SL1, SL2, SL3]) }}You can define up to 4 variants per tag.
vary() across multiple fields, every tag must have the same number of variants. Variant 1 of the subject always sends with Variant 1 of the preview, and so on.Whitespace Control
If you notice an unexpected blank space at the top of your template, add dashes to your capture tags to remove it. This is called dash syntax ({%- and -%}), and it trims whitespace around the tag.
Adding Personalization
Drop your personalization tag directly inside the capture block:
{%- capture SL1 -%}Hey {{ customer.FIRST_NAME | default: "there" }}, your offer is here{%- endcapture -%}
{%- capture SL2 -%}Don't wait, {{ customer.FIRST_NAME | default: "there" }} — offer ends Sunday{%- endcapture -%}
{{ vary([SL1, SL2]) }}Use | default: "text" to gracefully catch missing attribute values.
Varying Data Connections and Content Blocks
The same pattern works for data connections and content blocks. Add them inside capture blocks. They can be combined with text and other personalization tags if needed.
Data connections:
{%- capture DC1 -%}{{ data_connection('DC_a09f78a7-5b70-4a45-9316-0bf40d150dc4', customer.SUPPORTER, 'Supporter') | default: 'Your Team' }}{%- endcapture -%}
{%- capture DC2 -%}{{ data_connection('DC_b19f78a7-5b70-4a45-9316-0bf40d150dc5', customer.SUPPORTER, 'Supporter') | default: 'Your Team' }}{%- endcapture -%}
{{ vary([DC1, DC2]) }}Content blocks:
{%- capture CB1 -%}{{ content_block('promo-1-nv5kheabuz') }}{%- endcapture -%}
{%- capture CB2 -%}{{ content_block('promo-2-qr7wjdcytx') }}{%- endcapture -%}
{{ vary([CB1, CB2]) }}Insert into Your Template
Subject line & preview text: Paste your full Liquid block directly into the field. These fields accept Liquid natively.
Body: For email body content variations, the Liquid is split into two parts:
-
Place your
capturestatements at the top of the template using dash syntax ({%- -%}) so they render invisibly:{%- capture BODY1 -%}Here's a gift to help you bounce back! 🎁{%- endcapture -%} {%- capture BODY2 -%}A special surprise to change your luck! 🎁{%- endcapture -%} {%- capture BODY3 -%}Unlock a treat to get things moving! 🎁{%- endcapture -%} {%- capture CTA1 -%}Claim Your Bonus{%- endcapture -%} {%- capture CTA2 -%}Deposit & Play Now{%- endcapture -%} {%- capture CTA3 -%}Unlock My Gift{%- endcapture -%} {%- capture CTA4 -%}Boost My Balance{%- endcapture -%} -
Place the
vary()snippet into each body component you want to vary:{{ vary([BODY1, BODY2, BODY3, BODY4]) }} {{ vary([CTA1, CTA2, CTA3, CTA4]) }}
SMS
Message text: Paste your Liquid block into the message text field in the SMS template editor.
Push Notifications
Title and/or body: Paste your Liquid block into either field. If you vary both, the same-number-of-variants rule applies.
Validate, Preview, and Test
- Validate. The Template Editor automatically checks for syntax errors when you save. It also scans the template to ensure the number of content variants is consistent throughout. If personalization tags aren't rendering, check for validation errors and confirm you are using a Liquid template.
- Preview. Click Preview in the Template Editor. Click the refresh button to view a different variation at random.
- Send a test to cycle through your variables, testing each template variation individually.
{{ customer.FIRST_NAME }}), wrap it in render() so the nested Liquid resolves in the preview window: {{ render(data_connection('DC_...', ...)) }}
vary() to select a single variable from the array.Best Practices
-
Keep variant counts consistent: Use the same number of variants in every
vary()tag across the template so variants stay paired 1:1. -
Use dash syntax: Write
{%-and-%}on yourcapturetags to avoid unexpected blank space. -
Always set a default: Add
| default: "text"to personalization tags and data connections so missing values don't break the message. -
Wrap Liquid-returning data connections in
render(): This makes nested Liquid resolve correctly in preview. - Add a tracked link to SMS variations: Without one, SMS variant performance can't be measured.
- Preview and test every variant before you launch, especially when a variant includes a content block or data connection.
Next: Launch your campaign. See Sending a Campaign with Content Variation.