带有“每个循环”把手的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

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
        },
}

while using handlebars as the merge language 'title' is the reserved helpername which is used in handlebars which makes your text in title case. If you do only {{title}} by default it considers as title the empty text. try giving it {{title title}} which should work or changing the key name to something else ( if you dont want your title in title case )

https://mandrill.zendesk.com/hc/en-us/articles/205582537-Using-Handlebars-for-dynamic-content Use this link to use handle bars in your code its so easy with global variables.

Mandrill decided to create custom handlebars helpers with some horrible, HORRIBLE names:

https://mandrill.zendesk.com/hc/en-us/articles/205582537-Using-Handlebars-for-Dynamic-Content#inline-helpers-available-in-mandrill

title and url will definitely give you grief if your objects happen to have keys named title and urlas well. Why they didn't name their helpers something like toTitleCase and encodeUrl is beyond me.

As far as arrays and #each is concerned, you can work around it by using {{this.title}} instead of {{title}}.