Template Variables¶
Template variables let you personalize your campaigns with subscriber-specific data. When MailJawn sends your email, each variable is replaced with the actual value for that subscriber.
Syntax¶
Variables use double curly braces:
You can use variables anywhere in your MJML — subject lines, text blocks, links, and image URLs.
Available Variables¶
Subscriber Variables¶
| Variable | Description | Example Value |
|---|---|---|
{{ subscriber.email }} |
The subscriber's email address | maya@example.com |
{{ subscriber.name }} |
The subscriber's name (blank if not set) | Maya Chen |
{{ subscriber.custom_fields.KEY }} |
Any custom field you've defined | {{ subscriber.custom_fields.plan }} → pro |
Organization Variables¶
| Variable | Description | Example Value |
|---|---|---|
{{ company_name }} |
Your organization's name (from account settings) | Recipe Box Inc. |
{{ address }} |
Your organization's mailing address | 123 Main St, Austin, TX 78701 |
Links¶
| Variable | Description |
|---|---|
{{ unsubscribe_url }} |
A one-click unsubscribe link unique to each subscriber |
Using Variables in MJML¶
In Text¶
In Subject Lines¶
Your campaign subject line supports variables too:
In Links¶
<mj-button href="https://example.com/profile?email={{ subscriber.email }}">
View Your Profile
</mj-button>
Filters¶
Variables support Jinja2 filters for formatting. Apply a filter with the pipe (|) character:
Common Filters¶
| Filter | What It Does | Example | Result |
|---|---|---|---|
default('value') |
Provides a fallback when the variable is empty | {{ subscriber.name \| default('there') }} |
there (if name is blank) |
upper |
Converts to UPPERCASE | {{ subscriber.name \| upper }} |
MAYA CHEN |
lower |
Converts to lowercase | {{ subscriber.name \| lower }} |
maya chen |
title |
Converts To Title Case | {{ subscriber.name \| title }} |
Maya Chen |
capitalize |
Capitalizes the first letter | {{ "hello" \| capitalize }} |
Hello |
trim |
Removes leading/trailing whitespace | {{ subscriber.name \| trim }} |
Maya Chen |
replace('old', 'new') |
Replaces text | {{ subscriber.email \| replace('@', ' at ') }} |
maya at example.com |
Chaining Filters¶
You can combine multiple filters:
This first falls back to "Friend" if the name is empty, then ensures it's in Title Case.
Conditional Content¶
Use {% if %} blocks to show content only when a condition is met:
<mj-text>
{% if subscriber.name %}
Hi {{ subscriber.name }},
{% else %}
Hi there,
{% endif %}
Here's what's new this week.
</mj-text>
Checking Custom Fields¶
<mj-text>
{% if subscriber.custom_fields.plan == 'pro' %}
As a Pro user, you get early access to new recipes.
{% else %}
Upgrade to Pro for early access to new recipes.
{% endif %}
</mj-text>
How Missing Variables Are Handled¶
If a variable doesn't exist or is empty, MailJawn renders it as an empty string — no raw {{ }} tags will ever appear in a sent email. This means it's safe to use variables even if not every subscriber has the field populated.
Use default for a Better Experience
Rather than leaving a blank space where a name should be, use the default filter:
This way subscribers without a name on file see "Hi there," instead of "Hi ,".
Security¶
Template variables are rendered in a sandboxed environment. Subscribers can't inject code or access data outside the variables listed above. All values are automatically HTML-escaped to prevent cross-site scripting.
Warning
The {{ unsubscribe_url }} variable is the one exception — it's not HTML-escaped because it's meant to be used inside an href attribute. Always place it in a link tag, not in visible text.