dimanche 12 avril 2015

Mandrill API with Handlebars "each loop" not working


Vote count:

0




Met problem when using Mandrill API to send transactional newsletters. I chose Handlebars for the template parameters. The user name was shown correctly, but data in the list (post titles) were empty. Please help indicate if anything I did wrong. Thank you!


The template is as below, sent to the endpoint /messages/send.json :



func genHTMLTemplate() string {
return "code generated template<br>" +
"Hi {{name}}, <br>" +
"{{#each posts}}<div>" +
"TITLE {{title}}, THIS {{this}}<br>" +
"</div>{{/each}}"
}


The API log in my Settings panel in mandrillapp.com shows the parameters:



{
"key": "xxxxxxxxxx",
"message": {
:
"merge_language": "handlebars",
"global_merge_vars": null,
"merge_vars": [
{
"rcpt": "xxxxxx@gmail.com",
"vars": [
{
"name": "posts",
"content": [
{
"title": "title A"
},
{
"title": "title B"
},
]
},
{
"name": "name",
"content": "John Doe"
}
]
}
],
:
},
:
}


And below is the email received:



code generated template
Hi John Doe,
TITLE, THIS Array
TITLE, THIS Array


asked 18 secs ago







Mandrill API with Handlebars "each loop" not working

Aucun commentaire:

Enregistrer un commentaire