gpt4 book ai didi

mailchimp - 如何从 MERGE VARS 中传递的数组中呈现带有 Mandrill 模板的列表

转载 作者:行者123 更新时间:2023-12-04 02:12:59 28 4
gpt4 key购买 nike

我必须用 merge_vars 进行替换.

{
"key":"some key",
"template_name":"order-confirmation",
"template_content":[
{
"name":"ORDERNUMBER",
"content":"12312312321"
},
{
"name":"PRICE",
"content":"35.10"
},
{
"name":"NAME",
"content":"Some name"
},
{
"name":"PICKUPDATE",
"content":"2013-05-10"
},
{
"name":"ORDERITEMS",
"content":[
{
"NUMPRODUCTS":"26",
"PRODUCTNAME":"Milk",
"PRODUCTPRICE":"1.35 EUR"
}
]
},
{
"name":"SERVICENUMBER",
"content":"12345"
},
{
"name":"PICKUPPOINT",
"content":"AAA 350"
},
"message":{
"from_email":"support@support.com",
"to":[
{
"email":"asdasd@asda.com"
}
],
"subject":"Subject text",
"attachments":[

]
},
"async":false
}
}

我应该如何制作 html 占位符?我这样做了,但它不起作用。
我只对 ORDERITEMS 感兴趣.
<tr>
<td>*|ORDERITEMS:NUMPRODUCTS|*</td>
<td>*|ORDERITEMS:PRODUCTNAME|*</td>
<td>*|ORDERITEMS:PRODUCTPRICE|*</td>
</tr>

最佳答案

据我所知,使用 Mandrill 中的普通模板引擎,content 唯一支持的类型|属性为 string ,所以没有办法提供结构。

最近,(2015 年 1 月 13 日)Mandrill 宣布支持 Handlebars 模板,因此,可以在 content 中包含数组。 .

http://blog.mandrill.com/handlebars-for-templates-and-dynamic-content.html

使用这种新的模板语言,不仅可以根据需要访问子属性,甚至可以在数组内部循环,甚至可以嵌套 do 循环。 (参见博客文章中的 this comment)

这是从博客文章中提取的用于执行循环的示例:

合并变量或模板内容:

{
"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}}

关于mailchimp - 如何从 MERGE VARS 中传递的数组中呈现带有 Mandrill 模板的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16605718/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com