将变量传递给 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 编码的等效字符(例如 < 变成 <).
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.
!= 数据 ?>
详见标准&在此处强制打印脚本: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屋!