Templates
Create reusable email templates with Handlebars variable interpolation. You can manage templates through the Dashboard or the API.
Overview
Templates let you:
- Define email layouts once, reuse everywhere
- Use variables for personalization
- Version control your templates
- Preview before sending
Creating a Template
Via Dashboard
- Navigate to Templates in the sidebar
- Click Create Template
- Enter a template name and subject line
- Write your HTML content with
{{variables}} - Preview the rendered output with sample data
- Click Save
Via API
curl -X POST https://api.zyphr.dev/v1/templates \
-H "X-API-Key: zy_live_your_key" \
-H "Content-Type: application/json" \
-d '{
"name": "welcome-email",
"subject": "Welcome, {{name}}!",
"html": "<h1>Hello {{name}}</h1><p>Thanks for joining!</p>",
"text": "Hello {{name}}, Thanks for joining!"
}'
const template = await zyphr.templates.create({
name: 'welcome-email',
subject: 'Welcome, {{name}}!',
html: '<h1>Hello {{name}}</h1><p>Thanks for joining!</p>',
text: 'Hello {{name}}, Thanks for joining!',
});
Managing Templates
Via Dashboard
From the Templates page you can:
- View all templates with search and pagination
- Edit a template's name, subject, HTML content, and plain text fallback
- Preview the rendered output with sample variable data
- Duplicate a template to create a variation
- Send a test email to verify how it looks in a real inbox
- Delete templates that are no longer needed
Via API
# List templates
curl https://api.zyphr.dev/v1/templates \
-H "X-API-Key: zy_live_your_key"
# Get a template by ID
curl https://api.zyphr.dev/v1/templates/TEMPLATE_ID \
-H "X-API-Key: zy_live_your_key"
# Get a template by name
curl https://api.zyphr.dev/v1/templates/name/welcome-email \
-H "X-API-Key: zy_live_your_key"
# Update a template
curl -X PATCH https://api.zyphr.dev/v1/templates/TEMPLATE_ID \
-H "X-API-Key: zy_live_your_key" \
-H "Content-Type: application/json" \
-d '{
"subject": "Welcome aboard, {{name}}!",
"html": "<h1>Welcome {{name}}!</h1><p>Let'\''s get started.</p>"
}'
# Delete a template
curl -X DELETE https://api.zyphr.dev/v1/templates/TEMPLATE_ID \
-H "X-API-Key: zy_live_your_key"
Using Variables
Templates use Handlebars syntax:
<h1>Hello {{name}}</h1>
<p>Your order #{{order.id}} has shipped!</p>
{{#if premium}}
<p>Thanks for being a premium member!</p>
{{/if}}
{{#each items}}
<li>{{this.name}} - ${{this.price}}</li>
{{/each}}
Sending with a Template
curl -X POST https://api.zyphr.dev/v1/emails \
-H "X-API-Key: zy_live_your_key" \
-H "Content-Type: application/json" \
-d '{
"to": "user@example.com",
"template_id": "welcome-email",
"template_data": {
"name": "John",
"order": { "id": "12345" },
"premium": true,
"items": [
{ "name": "Widget", "price": 9.99 },
{ "name": "Gadget", "price": 19.99 }
]
}
}'
await zyphr.emails.send({
to: 'user@example.com',
templateId: 'welcome-email',
templateData: {
name: 'John',
order: { id: '12345' },
premium: true,
items: [
{ name: 'Widget', price: 9.99 },
{ name: 'Gadget', price: 19.99 },
],
},
});
Preview & Testing
Via Dashboard
- Open a template from the Templates page
- Enter sample variable values in the preview panel
- Switch between HTML and Plain Text views
- Click Send Test to deliver a test email to your inbox
Via API
# Render a template with sample data
curl -X POST https://api.zyphr.dev/v1/templates/welcome-email/render \
-H "X-API-Key: zy_live_your_key" \
-H "Content-Type: application/json" \
-d '{"name": "John", "premium": true}'
# Send a test email
curl -X POST https://api.zyphr.dev/v1/templates/TEMPLATE_ID/test \
-H "X-API-Key: zy_live_your_key" \
-H "Content-Type: application/json" \
-d '{
"to": "test@example.com",
"data": { "name": "John" }
}'