gpt4 book ai didi

google-apps-script - Apps 脚本电子邮件 : HTML String not evaluating in Template Body

转载 作者:行者123 更新时间:2023-12-04 10:14:19 25 4
gpt4 key购买 nike

我似乎无法成功获取 html 字符串以显示在模板中。所有非 html 字符串值似乎都正确评估并显示在电子邮件中。我已经浏览了文档/堆栈溢出,似乎找不到任何关于此的具体内容。

应用脚本代码:

function sendReceiptEmail(order_id, data){
const exceptions = ["name", "address", "email", "total", "building_code", "status"];

var items = '';
for (item in data) {
if (exceptions.indexOf(item) == -1){
items += "<tr><td>" + item + "</td><td>" + data[item] + "</td></tr>"
}
}
var htmlBody = HtmlService.createTemplateFromFile('customer-email');

htmlBody.name = data.name;
htmlBody.order_id = order_id;
htmlBody.address = data.address;
htmlBody.email = data.email;
htmlBody.total = data.total;
htmlBody.building_code = data.building_code;
htmlBody.timestamp = getFormattedDate(new Date());
htmlBody.items = items;

var message = htmlBody.evaluate().getContent();
var subject = "Order #" + order_id;

MailApp.sendEmail({
to: data.email,
subject: subject,
htmlBody: message
});
};

HTML模板

<html>
<head>
<base target="_top">
</head>
<body>
<h2>Thanks for your order, <?= name ?></h2>
<p>Please see your order details below.</p>

<p><strong>Name: </strong><?= name ?></p>
<p><strong>Email: </strong><?= email ?></p>
<p><strong>Address: </strong><?= address ?></p>
<p><strong>Building Code: </strong><?= building_code ?></p>
<p><strong>Date: </strong><?= timestamp ?></p>
<br/>
<p><strong>Subtotal: </strong>$ <?= total ?></p>
<p><strong>Delivery Fee: </strong>$ 5.00</p>
<p><strong>Total: </strong>$ 5.00</p>

<h3><strong>Order Summary</strong></h3>
<table>
<tr>
<th>Item</th>
<th>Quantity</th>
</tr>
<?= items ?>
</table>

</body>
</html>

结果:
enter image description here

最佳答案

这个 retrofit 怎么样?我认为您的问题的原因是由于 <?=<?= items ?> . The official document说如下。

Printing scriptlets, which use the syntax , output the results of their code into the page using contextual escaping.


这种情况请修改为 <?!= . The official document说如下。

Force-printing scriptlets, which use the syntax <?!= ... ?>, are like printing scriptlets except that they avoid contextual escaping.


从:
<?= items ?>
到:
<?!= items ?>
引用:
  • HTML Service: Templated HTML
  • 关于google-apps-script - Apps 脚本电子邮件 : HTML String not evaluating in Template Body,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61153813/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com