Sendgrid中替代令牌列表 [英] List of Substitution Tokens in Sendgrid

查看:180
本文介绍了Sendgrid中替代令牌列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向单个用户发送一个单独的交易电子邮件,并希望在电子邮件中嵌入一个项目列表。我可以使用Node.js中的NPM软件包sendgrid添加单个替换值 - https://github.com / sendgrid / sendgrid-nodejs

I'm sending a single transactional email to a single user and want to embed a list of items in the email. I can add single substitution values using the NPM package "sendgrid" in Node.js - https://github.com/sendgrid/sendgrid-nodejs:

email.addFilter('templates', 'enable', 1);
email.addFilter('templates', 'template_id', '11122233445....');
email.addSubstitution('{{TOKEN1}}', 'My Token1 Replacement');

但我看不到如何在sendgrid中添加一个项目列表到模板。使用Mandrill我可以使用Handlebars并执行以下操作。列表:

But I can't see how add a list of items to the template in sendgrid. Using Mandrill I can use Handlebars and do the following. The list:

items: [
    {name: "one", url: "/one"},
    {name: "two", url: "/two"},
];

在模板中:

<ul>
    {{#each ITEMS}}
    <li>
        {{name}} - <a href="{{url}}">Blah</a>
    </li>
    {{/each}}
</ul>

然后在代码中:

var rcpt = { "rcpt": email, 
    "vars": [
        { "name":"ITEMS", "content": items }
    ]
};
mergeVars.push(rcpt);
var message = { ...
    "merge_vars": mergeVars,
}
mandrillClient.messages.sendTemplate({... "message": message });

导致:

<ul>
    <li>one <a href="/one">Blah</a></li>
    <li>two <a href="/two">Blah</a></li>
</ul>

有没有办法在Sendgrid中执行此操作?

Is there a way to do this in Sendgrid?

推荐答案

SendGrid在模板中没有每个逻辑。

SendGrid doesn't have each logic in Templates.

最好的解决方法是在模板中:

The best workaround for this is to have in the Template:

<ul>
  {item1}
  {item2}
  {item3}
</ul>

然后在替换中,您可以填入相应的< li> ;项目1细节 或视情况而定。确保您的模板具有与最大列表大小一样多的替换标签,并且您具有NULL的这些项目的默认值,以便即使没有项目也可以填充。

Then in your substitutions, you'd populate either the appropriate <li> item 1 details</li> or NULL as the case may be. Make sure that your template has as many Substitution tags as your max list size, and that you have default values for those items of NULL, so that they're populated even if there's not an item.

这篇关于Sendgrid中替代令牌列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆