Objective
SendGrid's Email API supports dynamic subject lines to make sending messages easier and more convenient. This guide explains how to use Handlebars syntax to give your Dynamic Template a customizable subject line. To insert substitution tags into your email content or subject lines with Marketing Campaigns, see Adding Dynamic Content with Handlebars in Marketing Campaigns.
Product
SendGrid - Email API
Procedure
Dynamic Templates
This guide uses Dynamic Templates—if you don't already have one created, you'll need to create one from the Dynamic Templates page. To make sure the email subject can be specified in your API request, you'll need to use Handlebars syntax, and set your subject as {{{subject}}}
.
Please note, when using the Code Editor to view or modify your Dynamic Template, you'll need to click the Settings bar on the left edge of the window to edit the subject.
Sending your email
Once you have the Handlebars syntax in your Dynamic Template, you can create your API request, and the Handlebars tag(s) in your Dynamic Template will be replaced with the corresponding value(s) in the dynamic_template_data
object:
"dynamic_template_data": {
"subject": "Your dynamic subject"
},
This example will replace {{{subject}}}
in your Dynamic Template with the text, "Your dynamic subject".
Additional information
For more details on using Dynamic Templates with the Handlebars templating language, see: