Templates

Templates

Save reusable email content and render it with variables at send time.

A template is reusable email content — a name plus an optional subject, html, and text body. Instead of hard-coding the same markup in your app, save it once as a template and reference it by id when you send. Templates support {{ variable }} placeholders that you fill per send.

Create a template

Create templates from the dashboard (Templates → New) or via the API. Provide a name and at least one of html or text; subject is optional but recommended.

import { MailBlastr } from 'mailblastr';

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.templates.create({
  "name": "Welcome email",
  "subject": "Welcome, {{first_name}}!",
  "html": "<h1>Hi {{first_name}} 👋</h1>"
});
console.log({ data, error });

Variables

Anywhere in the subject, html, or text, write {{ key }} and pass matching variables when sending. Whitespace inside the braces is ignored, so {{first_name}} and {{ first_name }} are equivalent. Unknown placeholders render as an empty string, so a recipient never sees a raw {{ ... }} tag.

A template may contain up to 50 variables. We recommend capitalizing keys (e.g. PRODUCT_NAME). Each variable can declare a type of string or number and an optional fallback_value — the value used when you don't supply one at send time. If a variable has no fallback and you omit its value, the send fails with a validation error.

These variable names are reserved and cannot be used: FIRST_NAME, LAST_NAME, EMAIL, UNSUBSCRIBE_URL, contact, this.
Variables are simple string substitution — there is no logic (no conditionals or loops). For per-recipient marketing merge tags in bulk sends, see Campaigns.

Next