我正在尝试通过Mandrill发送模板电子邮件,但在模板提取我发送的数据时遇到问题。
The docs
假设我需要将数据转换为
[{ name: 'propertyName', content: 'the content' }]
他们给出的示例如下
数据
"global_merge_vars": [
{
"name": "user_name",
"content": "Mandrill_User1"
}
]
样板
<p>Thanks for registering! Your username is {{user_name}}.</p>
后果
<p>Thanks for registering! Your username is Mandrill_User1.</p>
在我的情况下,数据更加复杂。
我有点像
{
"firstname": "Tyler",
"lastname": "Durden",
"fullname": "Tyler Durden",
"email": "tyler.durden@testy.tes",
"company": {
"name": "Company 1",
"role": {
"slug": "supplier",
"name": "Supplier"
}
}
}
我转换为
name
:
content
配对如下,发送为
global_merge_vars
[
{ name: 'firstname', content: 'Tyler' },
{ name: 'lastname', content: 'Durden' },
{ name: 'fullname', content: 'Tyler Durden' },
{ name: 'email', content: 'tyler.durden@testy.tes' },
{
name: 'company',
content: [
{ name: 'name', content: 'Company 1' },
{
name: 'role',
content: [
{ name: 'slug', content: 'supplier' },
{ name: 'name', content: 'Supplier' }
]
}
]
}
]
我的模板是
主题
Dear {{user.firstname}} {{company.name}} has been approved.
身体
<html>
<body>
<p>Dear {{user.firstname}},</p>
<p>Your company {{company.name}} has been approved.</p>
</body>
</html>
但结果是
主题
亲爱的已批准。
身体
<html>
<body>
<p>Dear ,</p>
<p>Your company has been approved.</p>
</body>
</html>
我已经设置了要使用的Mandrill
handlebars
作为其模板语言。
我错过了什么?