将变量传递到HTML输出,然后传递到scriptlet [英] Passing variable to HTML output and then into a scriptlet
问题描述
Code.gs
function doPost(e) {
...
template.data += getCustomerData + "<br>";
}
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
index.html
...
<?= data ?>
显示的代码确实显示正确的值.但是,它不会将<br>
转换为html.我不确定为什么它不起作用,因为template.evaluate()
应该返回HtmlOutput对象.
The code shown does display the correct values. However, it doesn't translate <br>
into html. I'm not sure why it isn't working since template.evaluate()
is supposed to return an HtmlOutput object.
推荐答案
默认情况下,对字符串进行清理,将特殊字符转换为它们的HTML编码等效项(例如<成为& lt;).
By default the strings are sanitized, converting special characters to their HTML encoded equivalents (such as < becoming <).
在输出HTML时,必须使用<?!=来避免对数据进行清理.
When outputting HTML you must use <?!= to avoid sanitizing the data.
<?!= data ?>
查看有关标准&的详细信息;在此处强制打印脚本: https://developers.google.com/apps-script/guides/html/templates#standard_scriptlets
See the details on standard & force-printing scriptlets here: https://developers.google.com/apps-script/guides/html/templates#standard_scriptlets
这篇关于将变量传递到HTML输出,然后传递到scriptlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!