dongrenzheng1619 2015-04-12 09:53
浏览 40

带有“每个循环”把手的Mandrill API无法正常工作

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. "title A" and "title B" are expected after "TITLE".

code generated template
Hi John Doe,
TITLE, THIS Array
TITLE, THIS Array
  • 写回答

4条回答 默认 最新

  • doubinchou4219 2015-04-12 16:17
    关注

    After testing with Mandrill's sample code here I found the key "title" just doesn't work. Dunno the reason (a reserved keyword of Mandrill?) but replace it with "title1", "titleX" or something else it can be rendered correctly.

    {
        "name": "posts",
        "content": [
            {
               "title": "blah blah"  // "title1" or something else works
            },
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入