如何在使用把手的电子邮件开发中进行计算

How to calculate in email developing using handlebarJs

如您所见:

我想计算这个公式,它应该会返回值 (140) 但它没有用。我猜是因为 sendgrid 中的 handlebarjs 语法错误。那么如何正确地写呢。谢谢你帮助我:)

此处为 Twilio SendGrid 开发人员布道师。

Handlebars 是一种模板语言,支持 simple expressions. Expressions include rendering content, iterating over content and conditionals. There are also some built in helpers within Handlebars, like data formatting

但是,Handlebars 不会评估模板中的任意 JavaScript 代码。当您编写 {{ productNum1 + productNum2 + 100 }} 时,它是一个 JavaScript 表达式,在 JavaScript 解释器的上下文中,您希望计算出一个数字。 Handlebars 不是 JavaScript 解释器,因此它不会计算,这就是您的模板不计算公式的原因。

由于您 运行 使用此模板语法编写代码通过 SendGrid 发送电子邮件,因此您应该评估此类代码并将其作为要呈现的数据发送。