Templates and variables

Reusable email templates with Liquid variables like {{ first_name }}, defaults, aliases and the visual or HTML editor.

A template is a saved email design you can reuse in campaigns and API sends. Templates have a name, a subject, an optional preview text, and an alias like welcome that your code uses to pick it.

Create a template called welcome: greet them by first name, three short tips, and a Get started button linking to https://acme.com/start.

Update my welcome template so the subject mentions their company.

Send the welcome template to [email protected] from [email protected].

Your agent writes email-safe HTML and saves it with an alias you can reuse.

Two ways to edit#

  • Visual editor: write with headings, buttons, images and links. Maillayer wraps it in a clean, email-safe layout.
  • HTML: paste or write your own HTML. Use email-safe markup: tables and inline styles.

Variables#

Subjects and content can use Liquid variables. In campaigns, they come from the contact; in API sends, from the variables you pass.

VariableValue
{{ email }}The recipient's email address.
{{ first_name }}First name, if known.
{{ last_name }}Last name, if known.
{{ company }}Any custom contact property, by its name.
{{ unsubscribe_url }}Campaigns only: the recipient's unsubscribe link.

Give a fallback for missing values with the default filter:

Liquid
<h1>Hi {{ first_name | default: "there" }},</h1>

Liquid also supports conditions and loops, such as {% if plan == "Pro" %}…{% endif %}.

Save a template from code#

Templates with the same alias are updated, so you can keep them in your repository and sync on deploy:

cURL
curl https://agent.maillayer.com/api/v1/templates \
  -H "Authorization: Bearer $MAILLAYER_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome",
    "alias": "welcome",
    "subject": "Welcome to Acme, {{ first_name | default: \"there\" }}",
    "html": "<p>Thanks for joining.</p>"
  }'

See the Templates API.