【问题标题】:SendGrid map dynamicTemplateData to the same template multiple timesSendGrid 将 dynamicTemplateData 多次映射到同一个模板
【发布时间】:2021-12-15 20:56:21
【问题描述】:

我基本上希望能够为 dynamicTemplateData 提供一组对象。当 Sendgrid 中的模板收到此数据时,它应该在电子邮件中复制模板,为数组中的每个对象创建。这目前是否可行,还是我需要为每个对象发送单独的电子邮件?

【问题讨论】:

    标签: sendgrid


    【解决方案1】:

    这里是 Twilio SendGrid 开发人员宣传员。

    在 SendGrid 动态模板中,您使用把手将数据呈现到电子邮件中。如果您有一系列项目,您可以iterate through the array to render each of the object using the #each function

    以数据为例

    {
      "user": {
        "orderHistory": [
          {
            "date": "2/1/2018",
            "item": "shoes"
          },
          {
            "date": "1/4/2017",
            "item": "hat"
          }
        ]
      }
    }
    

    你可以这样写一个模板:

    <ol>
      {{#each user.orderHistory}}
       <li>You ordered: {{this.item}} on: {{this.date}}</li>
      {{/each}}
    </ol>
    

    它会渲染:

    <ol>
      <li>You ordered: shoes on: 2/1/2018</li>
      <li>You ordered: hat on: 1/42017</li>
    </ol>
    

    还有更多examples in the documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 2014-06-07
      • 2015-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多