admin管理员组文章数量:1336633
I was looking at this article:
.html
and then created a bunch of conditionals in my template like:
{{#if foo}}
<p>{{ foo }}</p>
{{/if}}
{{#if bar}}
<p>{{ bar }}</p>
{{/if}}
but it seems that if I do not provide foo
and bar
in my template data, the email does not get sent due to a render error. I also tried doing:
{{#if data.foo}}
<p>{{ data.foo }}</p>
{{/if}}
{{#if data.bar}}
<p>{{ data.bar }}</p>
{{/if}}
and giving { data: {} }
to the template data.. That does not work either.
How can I actually have a template that allows optional content?
I was looking at this article:
https://docs.aws.amazon/ses/latest/dg/send-personalized-email-advanced.html
and then created a bunch of conditionals in my template like:
{{#if foo}}
<p>{{ foo }}</p>
{{/if}}
{{#if bar}}
<p>{{ bar }}</p>
{{/if}}
but it seems that if I do not provide foo
and bar
in my template data, the email does not get sent due to a render error. I also tried doing:
{{#if data.foo}}
<p>{{ data.foo }}</p>
{{/if}}
{{#if data.bar}}
<p>{{ data.bar }}</p>
{{/if}}
and giving { data: {} }
to the template data.. That does not work either.
How can I actually have a template that allows optional content?
Share asked Nov 19, 2024 at 19:58 patrickpatrick 9,75213 gold badges65 silver badges126 bronze badges1 Answer
Reset to default 0Every variable referenced in your template must exist in the payload, even if the value is null or an empty string.
Before sending your payload to SES, ensure default values are set for missing variables:
{
"foo": null,
"bar": null
}
Like that you ensure that for example foo and bar will always be there, and you will not get rendering issue.
that's happening because AWS SES expects every referenced variable (even within {{#if}}) to be defined in the input payload. If data.foo or data.bar doesn’t exist in the payload (even if it’s referenced within a conditional), SES throws a rendering error.
So even optional variables, need to be defined in the payload to avoid rendering errors.
so if you're creating the payload somehow using code, you can update it to something like this:
const data = {
foo: userInput.foo || "",
bar: userInput.bar || null
};
本文标签: amazon web servicesHow can I do conditional content in an SES template with handlebarsStack Overflow
版权声明:本文标题:amazon web services - How can I do conditional content in an SES template with handlebars? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742401915a2468055.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论