问题
I'm trying to create a Handlebars template in Mandrill that will print out a list of items. We're using the {{#each}}
construct to do this:
{{#each bottles}}
<p>{{this.bottle_title}}</p>
<p>{{this.description}}</p>
<p>{{this.price}}</p>
{{/each}}
And, we're passing in JSON like this:
{/*...*/
'bottles' : [
{
"wine_id":"1599",
"bottle_title":"2012 Sapphire Hill \u2018Ketchum Reserve\u2019 Pinot Noir",
"description":"<p>\n <strong>Winemaker Notes:<\/strong><br \/>\n Blended from 4 clones, with 115 and 777 dominating to create this bold yet balanced wine. Aged for 20 months on French oak, this wine flaunts bright cherry, blackberry, and subtle vanilla with a very long finish.<br \/>\n <\/p>\n",
"price":"50"
},
{
"wine_id":"1600",
"bottle_title":"2012 Sapphire Hill \u2018D\u2019Argento\u2019 Pinot Noir",
"description":"<p>\n <strong>Winemaker Notes:<\/strong><br \/>\n D'Argento (Silver) was crafted for our 25th Anniversary and uses 4 clones from the fabled Ketcham Estate in Russian River Valley....<\/p>\n",
"price":"52"
}
] /*...*/
}
I've verified that if I just print out {{bottles}}
then I get the full JSON above outputted into the email. But {{#each bottles}}{{this.bottles}}{{/each}}
doesn't print out anything nor does the example we tried above. Any ideas how we can get this working?
Thanks so much for the help!
回答1:
When we considered that regular JSON was getting written to the email when we did {{bottles}}
we realized we were double-encoding the JSON. Doh! So for anyone else who runs into this issue, be sure you're not making the same silly mistake :)
来源:https://stackoverflow.com/questions/28705984/each-on-mandrill-is-resulting-in-an-empty-string