Reference
Temple template language
Temple fills variables, defaults and conditionals into email subjects, HTML and text at send time. Syntax, truthiness, escaping and where Temple runs.
Temple is Emailit’s small template language for subject lines, HTML and plain text. It isn’t Liquid or Handlebars: it supports variables, nested paths, default values and if/else blocks, and nothing else. Templates store placeholders as you write them, and Temple fills them in when an email is sent through the API, an automation or a campaign.
Syntax at a glance
{{first_name}} Variable
{{user.name}} {{items.0.sku}} Nested property and list item
{{first_name|"there"}} Default when the value is missing or null
{{#if plan}} … {{else}} … {{/if}} Conditional, with an optional elseTemple has no loops, filters, helpers, partials or custom functions. The only operator is the | default.
Variables
Hello {{first_name}}- Temple replaces
{{first_name}}with thefirst_namevalue you provide. Spaces inside the braces are ignored, so{{ first_name }}works too. - Names are case-sensitive:
{{First_Name}}doesn’t matchfirst_name. - A missing or
nullvalue becomes an empty string. Unknown placeholders disappear instead of showing up in the email. - Values are converted to text. Numbers and booleans appear as written (
42,true), and lists are joined with commas (["a","b"]becomesa,b). An object renders as[object Object], so point at one of its fields instead.
Nested properties and list items
Use dots to reach into objects, and numbers for list positions, starting at 0:
{{user.name}}
{{order.items.0.sku}}{
"user": { "name": "Ada" },
"order": { "items": [{ "sku": "A1" }, { "sku": "B7" }] }
}Because the dot separates path segments, a key that itself contains a dot can’t be reached. Use keys without dots.
Default values
Add | and a fallback to use when the value is missing or null:
Hi {{first_name|"there"}},
Your company: {{company|'Not set'}}Double quotes, single quotes or no quotes all work. The default isn’t used for an empty string, 0 or false; those render as empty, 0 and false. A default can’t contain the } character.
Conditionals
{{#if plan}}
Thanks for being on the {{plan}} plan.
{{else}}
You're on the free plan. Upgrade anytime from your dashboard.
{{/if}}{{else}}is optional.- A condition is false when the value is missing,
null,false,0, an empty string""or an empty list[]. Anything else is true, including the string"0", the string"false"and an empty object. - A condition is a single variable path, such as
planoruser.is_admin. There’s no==,and,or,notorunless. To branch on a value, compute a boolean in your code and pass it, for example"is_pro": true. - Write
{{else}}and{{/if}}exactly as shown, with no spaces inside the braces. - Temple processes conditionals first, then variables.
Blocks can be nested. Temple resolves the innermost blocks first, so every {{else}} and {{/if}} belongs to its own {{#if}}:
{{#if plan}}
{{#if annual}}Billed yearly.{{else}}Billed monthly.{{/if}}
{{else}}
You're on the free plan.
{{/if}}Nesting works up to 10 levels deep.
Escaping and special characters
Values aren’t HTML-escaped. Temple inserts values exactly as you pass them. A value such as Tom & Jerry or <b>Ada</b> goes into the HTML unchanged, so escape any user-supplied text in your code before you pass it. The same variables fill the subject, HTML and text, so an escaped value such as Tom & Jerry also appears that way in the subject and text. If that matters, pass a separate, escaped variable for the HTML.
This also means you can pass ready-made HTML, such as a table of order lines that your code renders, as a single variable.
There’s no escape syntax for double braces. Temple treats anything between {{ and }} as a placeholder and removes it if there’s no value. Single braces, such as those in CSS, are unaffected. Values are inserted once and not parsed again, so to show literal double braces, put them in a variable:
{
"html": "<p>Write {{example}} in your template to show the first name.</p>",
"variables": { "example": "{{first_name}}" }
}Where Temple runs
| Where | Temple runs? | What you can use |
|---|---|---|
Email API with a template |
Always | The variables you pass, and global |
Email API with inline subject, html or text |
When variables has at least one key, or the content uses {{global.…}} |
The variables you pass, and global |
| Automations, Send email step | On every send | Contact fields, tags, score, contact, global, unsubscribe_url, manage_subscriptions_url, payload, meta, run, automation and step, plus email in Email automations. See Automation emails. |
| Campaigns, test sends and Preview as contact | Always | Contact fields, cf, custom_fields, tags, score, global, unsubscribe_url, manage_subscriptions_url, webview_url and contact. See Campaigns. |
| SMTP relay | No | Nothing. The message is sent as you built it. |
| Dashboard editors and their previews | No | Editors insert placeholders, and their previews show them unrendered. The MJML editors (alpha) also preview Temple with sample data. To see a campaign rendered for one contact, use Preview as contact. |
API emails
Pass a template alias or tem_ ID, and a variables object. Fields you send in the request (subject, html, text) replace the template’s, then Temple renders the subject, HTML and text.
{
"from": "Acme <hello@acme.com>",
"to": "ada@example.com",
"template": "welcome-email",
"variables": {
"first_name": "Ada",
"plan": "Pro",
"activation_url": "https://acme.com/activate?token=8f3k2",
"cf": { "company": "Analytical Engines Ltd" }
}
}The dashboard editors insert {{cf.<key>}} for contact custom fields. In API sends, nothing is looked up from your contacts, so provide those values yourself under cf, as in the example. The same goes for {{unsubscribe_url}}: pass your own unsubscribe link if the template uses it. Global values are the exception: {{global.<key>}} is filled in from the workspace, unless your variables have a global key of their own.
You can also send inline content with variables and no template. See Send an email.
Automation emails
On every send, the Send email step renders the subject, HTML and text with Temple, whether they come from the template or from overrides on the step.
Contact automations put the contact’s fields at the top level, so these work:
{{email}},{{first_name}}and{{last_name}}{{cf.<key>}}or{{custom_fields.<key>}}for custom fields, for example{{cf.plan}}.{{cf.<key>}}is the form campaigns and the editors use.{{tags}}, the contact’s tags asvip, customer, and{{#if tags}}…{{/if}};{{score}}, the lead score{{unsubscribe_url}}, the contact’s unsubscribe link, also sent as one-clickList-Unsubscribeheaders in marketing emails, and{{manage_subscriptions_url}}, their manage subscriptions page{{contact.*}}, the same contact as an object, for example{{contact.first_name}}
All automations also get {{global.*}}, the workspace’s global values, {{payload.*}}, the data of the event that triggered the run, and {{meta.*}}, the run’s metadata. They also get {{run.id}}, {{automation.id}}, {{automation.name}} and {{step.key}}, the key of the Send email step. Email automations add {{email.*}}, the email that started the run, such as {{email.mail_from}}. Email and event automations don’t have a contact at the top level, so use {{payload.*}} or set the recipient and subject on the step.
Campaigns
Campaigns render the subject, HTML and text with Temple for each recipient, whichever editor built them. Test sends and Preview as contact render the same way. The variables come from the recipient’s contact:
{{first_name}},{{last_name}}and{{email}}{{unsubscribe_url}}, the recipient’s unsubscribe link, and{{manage_subscriptions_url}}, their manage subscriptions page{{cf.<key>}}or{{custom_fields.<key>}}for custom fields, for example{{cf.plan}}{{tags}}, the contact’s tags asvip, customer, and{{score}}, the lead score{{global.<key>}}, a global value, for example{{global.offer_url}}{{contact.*}}, the same fields as an object, for example{{contact.first_name}}
Empty contact fields count as missing, so defaults apply: {{first_name|"there"}} renders there for a contact without a first name. Test sends to an address that belongs to a contact in the workspace use that contact’s data. For other addresses, {{email}} is the test address and names and custom fields are empty.
Campaign merge tags written before campaigns used Temple keep working. The names first_name, last_name, email and unsubscribe_url, and the cf. prefix, match in any letter case, so {{FIRST_NAME}} still works. Custom field keys must match exactly. See Campaign merge tags.
SMTP
The SMTP relay accepts a finished message. There’s no template lookup and no Temple pass, so build the final HTML before you send, or use the API or an automation if you need variables.
Check templates before you publish
Emailit doesn’t reject a template or a send because of broken Temple syntax. Mistakes usually show up as missing text or leftover braces in the delivered email. MJML templates (alpha) are the exception: saving one checks its Temple and rejects unbalanced blocks. Before you publish:
- Check that every
{{#if …}}has a matching{{/if}}, and every{{has a closing}}. - Send the draft version to yourself by its
tem_ID with realisticvariables, including missing and empty values, to see both sides of each condition. See Template versions. - For a campaign, use Preview as contact with contacts that have and don’t have each value, then send a test. See Test and schedule.
Examples
A greeting with a fallback:
Hi {{first_name|"there"}},A block that depends on the plan:
{{#if plan}}
Your plan: {{plan}}
{{else}}
Upgrade anytime from your dashboard.
{{/if}}A subject with a nested value:
Order {{order.number}} has shipped, {{user.first_name|"friend"}}