什么标签<?=?>在Google脚本中意味着什么? [英] what the tag <?= ?> means in Google scripts?

查看:46
本文介绍了什么标签<?=?>在Google脚本中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标记<?=?> 是Google脚本的特定语法还是可以在纯html/javascript页面中使用?有任何描述吗?

Is the tag <?= ?> a specific syntax of Google scripts or it could work in a pure html/javascript page? Is there any description for it?

类似于<?= $ a;?> PHP标记,但是当我看到以下内容时我对此表示怀疑:< ;?var foo ="test";?> .

That is similar to <?=$a; ?> PHP tag but I doubted when I saw this: <? var foo = "test"; ?>.

推荐答案

在GAS文档中,这些代码正式称为脚本".它们是用于服务器端HTML呈现的Apps脚本语法.

Officially, these bits of code are referred to as 'scriptlets' in GAS documentation. They are Apps Script syntax for server-side HTML rendering.

在将HTML内容发送到您的浏览器以在客户端呈现< ;?之间的所有脚本之前??> <?!?> 被执行,它们的输出将附加到模板中.这些标记之间也可以只是纯文本,而不是脚本.在GAS中将HtmlTemplate转换为HtmlOutput对象时,将执行Scriptlet:

Before HTML content is sent to your browser for client-side rendering all scripts between <? ?> and <?! ?> are executed and their output gets appended to the template. It could also be just plain text between these tags instead of scripts. Scriptlets get executed when you convert an HtmlTemplate to a HtmlOutput object in GAS:

 //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服务器上执行.您是正确的,有许多模板引擎具有相同的功能,但实现方式不同.

The short answer is no. You can't run scriptlets directly in your browser - they are executed on Google Servers. You are correct that there are many templating engines that serve the same function but are implemented differently.

这篇关于什么标签&lt;?=?&gt;在Google脚本中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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