问题
I'm using Mandrill's send-template API method to send an email. It shouldn't matter, but just in case, I'm using PHP.
The email is delivered using the correct template, but none of the Handlebars variables are replaced with their values. Instead, they're merely removed.
Here's a full request as seen in the API Logs after reducing my code:
{
"template_name": "my-template-slug",
"template_content": [
{
"name": "price",
"content": "$25"
}
],
"message": {
"subject": "My Subject",
"from_email": "my@email.com",
"from_name": "My Name",
"to": [
{
"name": "Jimmy Crackcorn",
"type": "to",
"email": "jimmy@crackcorn.com"
}
]
},
"async": false,
"ip_pool": null,
"send_at": null,
"key": "my_api_key"
}
I also tried simplifying my template to just {{price}}
, which just sends a blank email.
I've also verified that Sending Defaults > Merge Language is set to Handlebars.
In case it makes any difference, I created the template in MailChimp and sent it to Mandrill, then removed the escaping back-slashes from the variables.
回答1:
Handlebars should be passed in the merge_vars
or global_merge_vars
parameters in your API request, not in template_content
—which is for mc:edit regions for the MailChimp template language.
来源:https://stackoverflow.com/questions/32392266/how-can-i-get-mandrill-to-parse-the-handlebars-tags-in-my-template