CORE MODULE

Build Conditional Content

What you'll learn in this guide

How to use conditional content in the Advanced HTML editor so a single template can show different content depending on the data you're sending — no need to build a separate template for every variation.

Overview

Conditional content lets you show different content to different recipients from the same template. Instead of building five versions of a template for five customer types, you build one template that adapts based on what's in the data file.

The Advanced HTML editor uses Razor syntax to handle this. Specifically, @if statements that check a field's value and decide what to show.

It's a small bit of logic with a big payoff. Once you've got the pattern down, you'll find yourself reaching for it more often than you'd expect.

When you'd use it

A few common scenarios where conditional content pays off:

  • Showing a different welcome message for new versus returning customers
  • Swapping product imagery based on what was purchased
  • Changing the call-to-action depending on subscription status
  • Adapting content for different countries, regions, or languages
  • Hiding a section entirely when it doesn't apply to a recipient

If you've ever thought "I wish I didn't have to build another version of this template," conditional content is probably what you need.

The basic syntax

At its simplest, an if statement looks like this:

@if (Model.Fields["product"] == "productname") {
<p>Variable content 1</p>
} else {
<p>Variable content 2</p>
}

‍

Here's what each part is doing:

  • @if tells the editor a condition is starting.
  • Model.Fields["product"] points to a field in your data file called product.
  • == "productname" checks whether that field equals exactly "productname".
  • The first set of curly braces holds the content that shows when the condition is true.
  • else gives you an alternative for when the condition isn't met.
  • The closing brace wraps up the statement.

Two things worth knowing up front. The field name in square brackets has to match the field name in your data file exactly. Not the label or description, the actual field name. And Razor is case-sensitive, so Product and product are treated as completely different fields.

‍

Build a basic if/else statement

  1. Open your template in the Advanced HTML editor.
  2. Place your cursor where the conditional content should appear.
  3. Add the opening @if statement, including the field name and value you want to check.
  4. Inside the first set of curly braces, add the HTML you want to show when the condition is met.
  5. If you want an alternative for when the condition fails, add an else block with its own curly braces and content.
  6. Close the statement with the final curly brace.
  7. Click Preview and run it against sample data to confirm the right content shows for the right conditions.

‍

A few patterns worth knowing

Check for more than two outcomes

Chain conditions together using else if when you've got more than two possible paths:

@if (Model.Fields["status"] == "premium") {
    <p>Welcome back, premium member!</p>
} else if (Model.Fields["status"] == "trial") {
    <p>Your trial ends soon.</p>
} else {
    <p>Welcome!</p>

‍

Show or hide a block entirely

You don't need an else block if you only want to show something under certain conditions. Skip it and the block simply won't appear when the condition isn't met.

@if (Model.Fields["country"] == "AU") {
    <p>Free shipping on orders over $100.</p>
}

‍

Handy for region-specific offers, optional disclaimers, or any content that only applies to a subset of recipients.

Nest conditions inside other conditions

You can place an @if statement inside another one when you need finer control. Just make sure every opening brace has a matching closing brace, otherwise the editor won't know where one condition ends and the next begins.

‍

Things to double-check before you go live

  • The field name in square brackets matches your data file exactly (not the field label).
  • The case matches — Product and product aren't the same.
  • Every { has a matching }.
  • Text values you're comparing against are wrapped in double quotes.
  • There's no stray space between @ and if.

Most issues with conditional content come down to one of these. A typo or mismatched case will fail silently and your content just won't show — no error, no warning, just an empty spot where the variable block should have been.

‍

Always preview with real data
‍
Run a preview using sample data that represents the different scenarios you're trying to cover. Test the "if" path, test the "else" path, and if you've used else if, test each branch. It's a quick check that saves you from finding out about a broken condition after the send goes out.

‍

That's it. Your template can now adapt to whoever's receiving it, so one well-built version can do the work of many.

‍