Sub topic 13
Previewing and testing with real and incomplete data
This chapter assumes you can send a campaign, understand contacts and fields, and have written merge tags with fallback values and conditional blocks. Here you will learn how to check that a personalised template works for every kind of recipient before you send it.
Why test with more than one contact
A personalised email is one template that renders differently for each person. A preview with a single clean test contact proves only that one path works. The failures happen on the other paths: an empty first name, a missing plan, an order with 40 items. Your goal is to test the template against the range of data your list really contains.
Build a set of test contacts
Create a small set of contacts, each one aimed at a different branch of the template.
| Test contact | What it checks |
|---|---|
| Complete record | The normal path renders correctly |
| Empty first name | The fallback replaces the blank |
| Field missing entirely | The tag does not print raw code or leave a gap |
| Each plan value (pro, free) | Each conditional branch shows the right text |
| Unknown plan value | The `else` branch runs |
| Very long name or order | Layout holds up and nothing is cut off |
| Order with one item | The loop renders a single line cleanly |
| Order with zero items | The loop produces no stray heading or empty list |
Where possible, also copy a few real records that you have permission to use, because real data contains oddities that invented data does not. These include extra spaces, all-capital names, and values such as "N/A". Follow your consent and data-minimisation rules when you do this, and use internal addresses for the test sends.
Preview, then send a test
Most platforms offer two checks. Run both, because they catch different problems.
- Preview as a contact. The platform renders the template with a chosen contact's data. This is fast and shows the text and fallbacks.
- Send a test email. The message goes through the real sending path to a real inbox. This shows how the subject line, preheader and layout look in actual email clients.
Make missing data fail loudly
Platforms often hide missing data by printing a blank. That is helpful for subscribers but bad for testing, because you cannot see the gap. In a test setting, you can make a missing field raise an error instead. The Jinja2 library, which uses syntax close to Liquid, does this with StrictUndefined.
from jinja2 import Environment, StrictUndefined
env = Environment(undefined=StrictUndefined)
template = env.from_string("Hi {{ first_name | default('there', true) }}, your plan is {{ plan }}.")
print(template.render(first_name="", plan="Pro"))
try:
template.render(first_name="Sam")
except Exception as error:
print(type(error).__name__)The first render prints Hi there, your plan is Pro. because the true argument tells default to replace empty strings as well as missing values. The second render has no plan, so it raises UndefinedError instead of sending a blank. Your email platform may not offer this option, so on those platforms you must test the missing-field cases by hand.
What to check in each preview
- The greeting reads naturally, with no double spaces, stray commas or "Hi ,".
- Each conditional branch shows the intended text, including the
elsebranch. - Loops show the correct number of lines, including one item and none.
- Links built from merge tags point to the right place. Click them.
- No raw tag text such as
{{ customer.first_name }}appears anywhere, including the subject line and preheader.
Exercise
Your template says "Hi {{ customer.first_name | default: "there" }}". A real contact has the first name "N/A". What does the email say, and how would you catch this before sending?
Show answer
It says "Hi N/A", because "N/A" is a non-empty value and the fallback only applies to empty or missing fields. Catch it by previewing real records (with permission) and by cleaning the data, for example by treating "N/A" as empty on import.
Exercise
Name three test contacts you would create for a template that loops over order items and shows different text for "pro" and "free" plans.
Show answer
Any three of: an order with one item, an order with zero items, a very large order, a "pro" contact, a "free" contact, and a contact with a missing or unknown plan.