我有一个 Postmark 电子邮件模板,其中动态变量包含 html。但是,它将 html 处理为纯文本。
更具体地说,我有下面的代码。变量 body
被发送到电子邮件模板,但是 <br><br>
显示为文本而不是它转到下一行。
在 Controller 中:
const body = "Hi...<br><br> Welcome to our a new episode.";
client.sendEmailWithTemplate(
{
TemplateAlias: process.env.POSTMARK_TEMPLATE,
TemplateModel: {
body: body
},
From: from,
To: email,
});
在邮戳模板中:
<tr>
<td>
1. The following includes text with a br break: {{body}}
</td>
</tr>
<tr>
<td>
2. This line includes a br break directly in the template: How are you? <br> Anything new?
</td>
</tr>
这会生成一封电子邮件,其中 br 中断在位置 2 上有效,但在位置 1 上无效。在位置 1 <br> <br>
显示为文本:“<br> <br>
”。
我做错了什么?
最佳答案
邮戳支持提供了答案:
We normally escape HTML but you can get around that by using this syntax for the variable:
{{{body}}} or {{&body}}
The triple braces or ampersand will let you put HTML into that variable when populating your TemplateModel values.
关于node.js - 邮戳模板 : dynamic variable with html processed as text instead of html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65054422/