Native Handlebars6 min read•Audience: All, Developers, Marketers
Using PostBrix with SendGrid
Deploy PostBrix templates to SendGrid Dynamic Templates or Single Sends, utilizing native Handlebars syntax.
Key Takeaways
- SendGrid Dynamic Templates use Handlebars syntax, making PostBrix templates almost 100% plug-and-play.
- In SendGrid, create a Dynamic Template and choose "Code Editor".
- Variables like {{firstName}} work natively without modification.
- Ensure you include SendGrid’s triple-curly unsubscribe tag: {{{unsubscribe}}}.
SendGrid Handlebars Compatibility#
SendGrid Dynamic Templates natively support Handlebars! This means variables and conditionals created in PostBrix work directly:
- Variables:
{{firstName}}(works out of the box) - Nested Objects:
{{order.number}}(works out of the box) - Loops:
{{#each items}}...{{/each}}(works out of the box) - Conditionals:
{{#if isVip}}...{{/if}}(works out of the box)
Important: In your footer, replace your placeholder unsubscribe link with SendGrid’s required tag:
code
html
Dispatching via SendGrid Mail Send API#
Dispatching your template with dynamic data using SendGrid’s Node.js SDK:
code
javascript
Frequently Asked Questions
Why should I use triple curly braces for {{{unsubscribe}}} in SendGrid?
SendGrid’s unsubscribe tag contains pre-built HTML anchor attributes. Using triple curlies prevents Handlebars from escaping the HTML characters.
Can I use PostBrix for SendGrid Single Sends (Marketing Campaigns)?
Yes. In Marketing Campaigns, create a Single Send, select "Custom HTML", and paste your PostBrix export.