将变量传递给 HTML 输出,然后传递给 scriptlet [英] Passing variable to HTML output and then into a scriptlet

查看:36
本文介绍了将变量传递给 HTML 输出,然后传递给 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 &lt;).

在输出 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆