Handlebars Variables
SendDock uses Handlebars as its template engine to personalize your emails with dynamic data. Variables allow you to insert subscriber-specific information into your messages.
Basic Syntax
Handlebars variables are written with double curly braces:
When you send the email with data:
{
"name": "John",
"company": "SendDock"
}
The result will be:
Hello John, welcome to SendDock!
Predefined Variables
SendDock includes some special variables that are always available:
{{email}}
The recipient subscriber's email.
{{unsubscribe_link}}
Required by law. Link for the user to unsubscribe.
All marketing emails must include a visible unsubscribe link. SendDock generates this link automatically and handles unsubscribes for you.
{{project_name}}
The name of the project from which the email is sent.
{{current_year}}
The current year (useful for copyrights).
Custom Variables (Metadata)
Any field you save in the subscriber's metadata is available as a variable.
Example: User with Metadata
When creating or importing a subscriber with this metadata:
{
"name": "Mary Garcia",
"company": "Tech Startup",
"role": "Founder",
"plan": "Pro",
"trial_ends": "2024-12-31"
}
You can use these variables in your template:
Result:
Hello Mary Garcia,
As Founder of Tech Startup, we want to inform you that your Pro plan expires on 2024-12-31.
Conditionals
Handlebars supports conditionals to show content only if a variable exists or meets a condition.
Check if Exists
If the subscriber has name in their metadata, it will show "Hello John!", otherwise just "Hello!".
Check Equality
SendDock uses standard Handlebars. For complex operations, check the official Handlebars documentation.
Multiple Conditionals
Loops (Arrays)
If your metadata includes arrays, you can iterate over them:
Metadata with Array
{
"name": "Carlos",
"purchased_items": [
"Product A",
"Product B",
"Product C"
]
}
Template with Loop
Result:
Hello Carlos,
Thanks for your purchase of:
<ul>
<li>Product A</li>
<li>Product B</li>
<li>Product C</li>
</ul>
Nested Variables
You can have complex objects in metadata:
{
"user": {
"name": "Ana",
"email": "ana@example.com",
"preferences": {
"language": "en",
"timezone": "America/New_York"
}
}
}
Access with dot notation:
Default Values
If a variable might not exist, use the || operator to provide a default value:
If name doesn't exist, it will show "Hello User,".
Date Formatting
If you have dates in metadata:
{
"subscription_date": "2024-01-15",
"renewal_date": "2024-02-15"
}
You can display them directly:
For more readable date formatting, save them already formatted in metadata from your backend before sending.
Example:
{
"formatted_date": "January 15, 2024"
}
Dynamic URLs
Create personalized links with variables:
HTML Escaping
By default, Handlebars escapes HTML for security. If you need to insert HTML:
Use triple braces {{{ instead of double {{.
Only use triple braces with content you completely control. Never with direct user input, to avoid XSS.
Common Use Cases
Welcome Email
Order Confirmation
Personalized Newsletter
Debugging Variables
If a variable doesn't display, check:
- Does it exist in metadata? Check the subscriber's JSON in the dashboard
- Correct name? Variables are case-sensitive:
{{Name}}≠{{name}} - Correct syntax? Double braces
{{variable}}, not{variable}or[[variable]] - Test send? Use "Send Test Email" with sample data to verify
Check Metadata in Dashboard
In the Subscribers section, click on a subscriber to see their metadata:
{
"name": "John Smith",
"company": "My Startup",
"plan": "pro"
}
Only these variables will be available: {{name}}, {{company}}, {{plan}}.
Limitations
Variables Not Available
These things are NOT available as variables:
- Data from other subscribers
- Project statistics (total subscribers, sends, etc.)
- User account information (current plan, billing, etc.)
- Environment variables or secrets
Metadata Size
Metadata has a limit of 64KB per subscriber. Avoid storing:
- Base64 images
- Arrays with thousands of elements
- Very long text (> 10,000 characters)
Sending Data via API
When sending an email with the API, pass the data in the data field:
await fetch('https://senddock.dev/api/v1/send', {
method: 'POST',
headers: {
'Authorization': 'Bearer sdk_...',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'user@example.com',
template: 'welcome-email',
data: {
name: 'John',
company: 'My Company',
plan: 'pro',
trial_ends: '2024-12-31'
}
})
});
If you send data in the API, it's merged with the subscriber's metadata. API data takes priority.