电子邮件模板中的循环

问题描述 投票:4回答:1

我们可以为SES模板创建一个for循环吗?

查看此处的代码(https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html),我看到的唯一示例是键值对。

语法看起来像我以前在handlebar.js中使用的语法。

类似这样的东西:

{
  "Template": {
    "TemplateName": "MyTemplate",
    "SubjectPart": "Greetings, {{name}}!",
    "HtmlPart": "<h1>Hello {{name}},</h1><p>Your favorite animals are {{#each animals}}<h1>{{favoriteanimal}}</h1>{{/each}}.</p>",
  }
}
amazon-web-services amazon-ses
1个回答
0
投票

是!

示例模板数据:

{
  "meta":{
    "userId":"51806220607"
  },
  "contact":{
    "firstName":"Anaya",
    "lastName":"Iyengar",
    "city":"Bengaluru",
    "country":"India",
    "postalCode":"560052"
  },
  "subscription":[
    {
      "interest":"Sports"
    },
    {
      "interest":"Travel"
    },
    {
      "interest":"Cooking"
    }
  ]
}

示例模板:

{
  "Template": {
    "TemplateName": "Preferences",
    "SubjectPart": "Subscription Preferences for {{contact.firstName}} {{contact.lastName}}",
    "HtmlPart": "<h1>Your Preferences</h1>
                 <p>You have indicated that you are interested in receiving 
                   information about the following subjects:</p>
                 <ul>
                   {{#each subscription}}
                     <li>{{interest}}</li>
                   {{/each}}
                 </ul>
                 <p>You can change these settings at any time by visiting 
                    the <a href=https://www.example.com/prefererences/i.aspx?id={{meta.userId}}>
                    Preference Center</a>.</p>",
    "TextPart": "Your Preferences\n\nYou have indicated that you are interested in 
                 receiving information about the following subjects:\n
                 {{#each subscription}}
                   - {{interest}}\n
                 {{/each}}
                 \nYou can change these settings at any time by 
                 visiting the Preference Center at 
                 https://www.example.com/prefererences/i.aspx?id={{meta.userId}}"
  }
}

可在此处找到更多信息:https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-advanced.html

© www.soinside.com 2019 - 2024. All rights reserved.