I am trying to send array of items to the Mandrill
template, but It's not working, the mail I receive shows the loop itself instead the data.
Here's my python code:
message = {
'text': '',
'html': '',
'preserve_recipients': False,
'to': [
{
'email': 'rohit@email.com',
'name': 'Rohit Khatri',
'type': 'to'
}
],
'merge_vars': [
{
'rcpt': 'rohit@email.com',
'vars': [
{
'name': 'name',
'content': 'Rohit Khatri'
},
{
'name': 'email',
'content': 'rohit@email.com'
}
]
}
],
'global_merge_vars': [
{
'name': 'notifications',
'content': [
{
'name': 'Rohit Khatri',
'profile_picture': 'http://rohitkhatri.com/profile_picture.jpg'
},
{
'name': 'John Doe',
'profile_picture': 'http://johndoe.com/profile_picture.jpg'
}
]
}
]
}
api = Mandrill('MANDRILL_KEY')
api.messages.send_template(
template_name = 'notification',
template_content = {},
message = message
)
Here's the template code:
{{#each notifications}}
<tr class="item">
<td valign="top" class="textContent">
<img src="{{profile_picture}}" width="50" height="75" class="itemImage"/>
<h4 class="itemName">{{name}}</h4>
</td>
</tr>
{{/each}}
And this is the output I'm getting on email:
{{#notifications}}
{{name}}
{{/notifications}}
It's not executing the loop, don't know what I'm doing wrong.
I was stuck with this same problem i added 'merge_language'=>'handlebars' in the message object and it solved my problem.