google-apps-script - 该标签在 Google 脚本中的含义是什么?
问题描述
标签<?= ?>
是谷歌脚本的特定语法还是可以在纯 html/javascript 页面中工作?有什么描述吗?
这类似于<?=$a; ?>
PHP 标签,但当我看到这个时我怀疑:<? var foo = "test"; ?>
.
解决方案
正式地,这些代码位在 GAS 文档中被称为“scriptlet”。它们是用于服务器端 HTML 渲染的 Apps 脚本语法。
在将 HTML 内容发送到浏览器以进行客户端渲染之前,<? ?>和<?! ?>被执行并且它们的输出被附加到模板中。它也可能只是这些标签之间的纯文本而不是脚本。当您在 GAS 中将 HtmlTemplate 转换为 HtmlOutput 对象时,Scriptlet 会被执行:
//HtmlTemplate instance
var htmlTemplate = HtmlService.createTemplate("<a href='<?!= www.google.com ?>'>Google</a>");
//HtmlOutputInstance - calling evaluate() fires off the scriptlets and
//creates HTML output that is ready to be sent to the client.
var htmlOutput = htmlTemplate.evaluate();
//Logs <a href='www.google.com'> Google </a>
Logger.log(htmlOutput.getContent());
最简洁的答案是不。您不能直接在浏览器中运行小脚本——它们是在 Google 服务器上执行的。您是正确的,有许多模板引擎提供相同的功能但实现方式不同。
推荐阅读
- c - libavcodec/libx264 不尊重 keyint_min
- octave - 在 linux 控制台中为 UTF-8 配置 Octave
- html - CSS 行距:未在元素中应用
- neo4j - Gremlin/Janusgraph 中的多个顶点标签是否可能,或者是否有更好的替代解决方案?
- arrays - 从文件中读取字符串并转换为数组 Julia
- android - 当片段返回的数据为空时,如何在视图寻呼机中动态操作片段
- amazon-web-services - 如何为每个在aws中动态登录我的网站的用户创建子域
- r - 通过 id 重塑并保持其他变量不变
- visual-studio-2017 - 无法在代码中使用我安装的 NuGet 包
- angular - 可以为角材料中的垫子图标禁用制表位吗?