据我所知,在 Mandrill 中使用普通模板引擎,这是唯一支持的类型content
属性是string
,因此无法提供结构。
最近(2015 年 1 月 13 日)Mandrill 宣布支持车把模板,因此可以在content
.
http://blog.mandrill.com/handlebars-for-templates-and-dynamic-content.html http://blog.mandrill.com/handlebars-for-templates-and-dynamic-content.html
使用这种新的模板语言,不仅可以根据需要访问子属性,甚至可以在数组内循环,甚至嵌套 do 循环。 (看这条评论 http://blog.mandrill.com/handlebars-for-templates-and-dynamic-content.html#comment-1812033668在博客文章中)
这是从博客文章中提取的用于执行循环的示例:
合并变量或模板内容:
{
"name": "products",
"content": [
{
"img": "http://kbcdn.mandrill.com/nesting-penguin.png",
"qty": 2,
"sku": "PENG001",
"name": "Penguin",
"description": "Solid wood, hand-painted penguin nesting doll with 5 different sizes included. Limited Edition.",
"price": "12.99",
"ordPrice": "25.98"
},
{
"img": "http://kbcdn.mandrill.com/nesting-bear.png",
"qty": 3,
"sku": "BBEAR001",
"name": "Brown bear",
"description": "Solid wood, hand-painted brown bear nesting doll. Coordinates with our entire Bear collection. Includes 6 nested sizes.",
"price": "12.99",
"ordPrice": "38.97"
}
]
}
这是在模板中使用它的方法:
{{#each products}}
<tr class="item">
<td valign="top" class="textContent">
<img src="{{img}}" width="50" height="75" class="itemImage" />
<h4 class="itemName">{{name}}</h4>
<span class="contentSecondary">Qty: {{qty}} x ${{price}}/each</span><br />
<span class="contentSecondary sku"><em>{{sku}}</em></span><br />
<span class="contentSecondary itemDescription">{{description}}</span>
</td>
<td valign="top" class="textContent alignRight priceWidth">
${{ordPrice}}
</td>
</tr>
{{/each}}
对于你的情况,你可以这样做:
{{#each ORDERITEMS}}
<tr>
<td>{{NUMPRODUCTS}}*</td>
<td>{{PRODUCTNAME}}</td>
<td>{{PRODUCTPRICE}}</td>
</tr>
{{/each}}