Templates
Create reusable email templates with dynamic variables.
Overview
Templates allow you to create reusable email layouts with variable placeholders. Use double curly braces {{variable}} to insert dynamic content.
Creating a template
Create a template via the API or dashboard:
// POST /api/templates
{
"name": "Welcome Email",
"slug": "welcome-email",
"subject_template": "Welcome to {{company}}, {{name}}!",
"html_template": "<h1>Hello {{name}}!</h1><p>Welcome to {{company}}. We're excited to have you.</p>",
"text_template": "Hello {{name}}! Welcome to {{company}}."
}Using a template
Reference the template by its slug and pass the variables:
// POST /api/send
{
"from": "welcome@yourdomain.com",
"to": "user@example.com",
"template": "welcome-email",
"data": {
"name": "John",
"company": "Acme Inc"
}
}This will render the email as:
Subject: Welcome to Acme Inc, John!
Hello John!
Welcome to Acme Inc. We're excited to have you.
Conditional content
Use conditionals to show or hide content based on variables:
<h1>Hello {{name}}!</h1>
{{#if isPremium}}
<p>Thank you for being a premium member!</p>
{{else}}
<p>Upgrade to premium for exclusive benefits.</p>
{{/if}}
{{#if items}}
<ul>
{{#each items}}
<li>{{this.name}} - {{this.price}}</li>
{{/each}}
</ul>
{{/if}}Available syntax
| Syntax | Description |
|---|---|
{{variable}} | Insert a variable value |
{{#if var}}...{{/if}} | Conditional block |
{{#each items}}...{{/each}} | Loop over an array |
{{#unless var}}...{{/unless}} | Negative conditional |
{{{html}}} | Insert raw HTML (unescaped) |