Skip to content
Open in

Conditional Content ​

This feature is available with the Plugin for Business plan and higher.

If you're on the Plugin for Startup or Plugin Expansion plan, consider upgrading to access this feature. For more details, visit our pricing page or contact support.

Conditional Content lets a single section carry several variants, each shown only when its condition matches. It covers audience personalization and A/B structures, and the variants are edited visually inside the editor rather than written as raw syntax.

More detail on the feature is available in our support article.

Enabling conditional content ​

Add the following option to TOPOL_OPTIONS:

ts
enableSectionVariants: true,

This setting unlocks the UI for adding and managing conditional variants of sections directly inside the editor interface.

Adding and managing section variants ​

  • Add structure variant
Variants
  • Add condition for certain variant
Variants
  • Switch between variants and edit its content
Variants

Conditions play very nice together with Merge Tag Previews.

Conditional syntax ​

The generated syntax is compatible with Mailchimp, SparkPost and Jinja, selected through emailServiceProvider:

ts
emailServiceProvider: 'mailchimp' | 'sparkpost' | 'jinja',

With jinja the conditions are exported as {% if %} / {% elif %} / {% else %} / {% endif %} statements that evaluate the Merge Tag as a variable, so the template can be rendered by any Jinja-compatible engine (Jinja2, Nunjucks, Twig-like engines with the same syntax).

We are eager to expand our compatibility with additional providers. If you have a specific provider in mind, please reach out to our support team with your request.

Comparators ​

Each condition combines a Merge Tag, a comparator and a value. Nine comparators are available:

ComparatorMeaning
isValue matches exactly
is notValue does not match
existThe Merge Tag is present (hides the value field)
> < >= <=Numeric comparisons
is one ofValue matches any entry of a list (needs chaining)
is not one ofValue matches no entry of a list (needs chaining)

The four numeric comparators can be removed from the picker, leaving only is, is not, exist and the list comparators:

ts
disableExtendedComparators: true,

List comparators ​

is one of and is not one of compare the Merge Tag against a list of values instead of a single one. The value field turns into a list editor: type a value and press Enter, or pick entries from the Merge Tag's autosuggestions.

List comparator

A whole predefined array can be inserted in one click through suggestionSets on the Merge Tag. Each set has a name and its values; picking a set adds all of its values to the condition (values already present are not duplicated), and the list stays editable afterwards. This suits segments such as regions or country groups that are maintained on the host side:

ts
{
  value: "*|CITY|*",
  text: "City",
  label: "City",
  suggestions: ["PRAGUE", "BRNO", "OSTRAVA"],
  suggestionSets: [
    { name: "West Bohemia", values: ["PLZEN", "KLATOVY", "DOMAZLICE"] },
    { name: "Moravia", values: ["BRNO", "OSTRAVA", "OLOMOUC"] },
  ],
},

The values are stored in the template as a plain list, so a later change of a set on the host side does not alter conditions that were already saved.

None of the supported syntaxes has a list operator, so the editor expands the list into a chain of single comparisons at export time. COUNTRY is one of CZ, SK becomes:

*|IF:COUNTRY=CZ:OR:COUNTRY=SK|*             <!-- Mailchimp -->
{{if country == "CZ" or country == "SK"}}     <!-- SparkPost -->
{% if COUNTRY == "CZ" or COUNTRY == "SK" %}   <!-- Jinja -->

and COUNTRY is not one of CZ, SK becomes:

*|IF:COUNTRY!=CZ:AND:COUNTRY!=SK|*            <!-- Mailchimp -->
{{if country != "CZ" and country != "SK"}}    <!-- SparkPost -->
{% if COUNTRY != "CZ" and COUNTRY != "SK" %}  <!-- Jinja -->

The SparkPost export converts the field name to lowercase (COUNTRY becomes country). Mailchimp and Jinja keep it as written.

Because of that expansion, the list comparators are offered only when chaining is on. SparkPost and Jinja chain by default. With the Mailchimp syntax, set logicalOperatorsInsideVariant: true.

A list comparator sets the operator for the whole variant, and the operator shows "Set by the list condition" instead of a dropdown:

  • is one of sets it to OR.
  • is not one of sets it to AND.

The export never nests conditions in parentheses, so one variant can't combine the two list comparators. Once a variant has several conditions, the list comparator that doesn't match the operator is greyed out in the picker. Its tooltip reads "Available only with OR between conditions" or "Available only with AND between conditions". To use it anyway:

  • If you chose the operator, switch the operator first, then pick the comparator.
  • If a list comparator set the operator, change that condition to another comparator first.

In the saved template JSON the list is stored next to the single value:

json
{
  "conditionField": "COUNTRY",
  "conditionComparator": "is one of",
  "conditionValue": "",
  "conditionValues": ["CZ", "SK"]
}

Chaining conditions ​

Chaining connects several conditions on one variant with AND or OR. It is controlled by logicalOperatorsInsideVariant, and the editor can export it for every provider:

ts
logicalOperatorsInsideVariant: true,
Variants

When the option is left unset, SparkPost and Jinja turn chaining on and Mailchimp leaves it off. Setting it explicitly overrides that default in either direction. With the Mailchimp syntax, turn it on only if your email service evaluates :AND: and :OR: inside a condition, such as *|IF:COUNTRY=CZ:OR:COUNTRY=SK|*. The option also unlocks the list comparators, which rely on chaining under the hood.

Merge tag-specific autosuggestions ​

Autosuggestions offer known values for a Merge Tag while a condition is being written, which cuts down on typos. Define them by adding a suggestions array to the Merge Tag configuration, so each Merge Tag carries its own list:

ts
{
  value: "*|COUNTRY|*",
  text: "Country",
  label: "Free Shipping Countries",
  // available suggestions for this specific Merge Tag
  suggestions: ['USA','Germany','France','Spain'],
},

The dropdown opens once a Merge Tag is selected and the user starts typing in the value field, or clicks the caret icon inside it. Suggestions are a convenience rather than a constraint, so any other value can still be typed in. With the list comparators the same array doubles as a pick list: each click adds the suggestion to the condition's values, and suggestionSets insert a whole named list at once.

Merge tag autocomplete

For more information about Merge Tags, visit this documentation.

Language-based variants ​

When using multilingual templates, a variant can be limited to specific languages, which suits a section that belongs in one language but not the others.

With multilingual enabled and two or more languages on the template, a language merge tag is added to the variant condition autocomplete. Its default name is TOPOL_TEMPLATE_LANG.

To create a language-based variant:

  1. Add a variant to a section
  2. Type TOPOL_TEMPLATE_LANG into the condition field
  3. Choose the language code from the suggested values (e.g., cs, en, de)

The suggested values come from the languages configured on the template. Selecting one also switches the editor to that language, so the variant is edited in context.

Custom language merge tag ​

The merge tag name is configurable via TOPOL_OPTIONS:

ts
languageMergeTag: 'MY_CUSTOM_LANG_TAG',

If not set, the default value is TOPOL_TEMPLATE_LANG.

When sending emails, set the value of this merge tag to the recipient's language code to control which variant is displayed.