Шаблон Mandrill не зацикливается на массиве - PullRequest
0 голосов
/ 29 декабря 2018

Я пытаюсь отправить массив элементов в шаблон Mandrill, но он не работает, полученное письмо отображает сам цикл вместо данных.

Вот мой код Python:

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
)

Вот код шаблона:

{{#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}}

И вот что я получаю по электронной почте:

{{#notifications}}
{{name}}
{{/notifications}}

Это не выполнение цикла, не знаючто я делаю не так.

1 Ответ

0 голосов
/ 11 января 2019

Я застрял с этой же проблемой, я добавил 'merge_language' => 'handlebars' в объект сообщения, и это решило мою проблему.

...