Mandrill 模板不在阵列上循环

我正在尝试将项目数组发送到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}}

它没有执行循环,不知道我做错了什么。


繁华开满天机
浏览 151回答 1
1回答

烙印99

我遇到了同样的问题,我在消息对象中添加了 'merge_language'=>'handlebars',它解决了我的问题。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python