[英]Google Apps Script with multiple stylesheet & js links
I'm new to Google Apps Scripts and am trying to implement a spacegallery into my google site. 我是Google Apps脚本的新手 ,正在尝试在我的Google网站中实现一个太空画廊 。
I have separated my css stylesheets & .js files into .html in the script editor and written my html page(minigallery.html), and now I'm trying to link them all in the Code.gs section. 我已经在脚本编辑器中将css样式表和.js文件分离为.html,并编写了html页面(minigallery.html),现在我试图在Code.gs部分中将它们链接在一起。 Here's what I have so far having used examples from here: https://developers.google.com/apps-script/guides/html/best-practices#separate_html_css_and_javascript
到目前为止,这里是我在这里使用示例的内容: https : //developers.google.com/apps-script/guides/html/best-practices#separate_html_css_and_javascript
Here's what I currently have in my Code.gs, but when I run the published version the css & js files appear not to be linked (granted I haven't put pics yet). 这是我目前在Code.gs中拥有的内容,但是当我运行发布的版本时,css和js文件似乎没有链接(请允许我还没有放入图片)。 You can find the published link here:
您可以在此处找到发布的链接:
//script.google.com/macros/s/AKfycbybCtW9y-iCT81WvBoCmfGnXWhSwQ5dpa7xyHU_H1ot/dev //script.google.com/macros/s/AKfycbybCtW9y-iCT81WvBoCmfGnXWhSwQ5dpa7xyHU_H1ot/dev
`
// Script-as-app template.
function doGet() {
var app = UiApp.createApplication().setTitle('Business Card Mini Gallery | MAvC Graphics.').setHeight(50).setWidth(100)
return HtmlService.createTemplateFromFile('minigallery')
.evaluate();
}function include(customcss) {
return HtmlService.createHtmlOutputFromFile('customcss')
.getContent();
}function include(layoutcss) {
return HtmlService.createHtmlOutputFromFile('layoutcss')
.getContent();
}function include(minigallerycss) {
return HtmlService.createHtmlOutputFromFile('minigallerycss')
.getContent();
}function include(eyesjs) {
return HtmlService.createHtmlOutputFromFile('eyejs')
.getContent();
}function include(jqueryjs) {
return HtmlService.createHtmlOutputFromFile('jqueryjs')
.getContent();
}function include(layoutjs) {
return HtmlService.createHtmlOutputFromFile('layoutjs')
.getContent();
}function include(utilsjs) {
return HtmlService.createHtmlOutputFromFile('utilsjs')
.getContent();
}function include(minigalleryjs) {
return HtmlService.createHtmlOutputFromFile('minigalleryjs')
.getContent();
}
` And here is my ill-written minigallery.html code to link the css & js (the first & last lines being the most important): `这是我写得不好的minigallery.html代码,用于链接css和js(第一行和最后一行是最重要的):
<?!= include('customcss'), ('layoutcss'), ('minigallerycss'); ?>
...//lengthy inner page code
<?!= include('eyejs'), ('jqueryjs'), ('layoutjs'), ('minigalleryjs'), ('utilsjs'); ?>
To complicate things I renamed the whole thing from spacegallery to minigallery, but I've already changed all of the files appropriately. 为了使事情复杂化,我将整个事情从spacegallery重命名为minigallery,但是我已经适当地更改了所有文件。
You only need one function named include
. 您只需要一个名为
include
函数。 Right now you have lots of functions all named "Include". 现在,您有许多名为“ Include”的功能。
The name of the file to look up is passed to the include
function: 要查找的文件名传递给
include
函数:
<?!= include('Stylesheet'); ?>
In the above line, Stylesheet
is the name of the file to get the contents from. 在上面的行中,
Stylesheet
是从中获取内容的文件的名称。 Instead of having multiple functions, you need multiple scriptets. 除了具有多个功能之外,您还需要多个脚本集。
<?!= include('customcss'); ?>
<?!= include('layoutcss'); ?>
<?!= include('minigallerycss'); ?>
<?!= include('eyesjs'); ?>
<?!= include('jqueryjs'); ?>
etc.
In your .gs file, just have one include statement: 在您的.gs文件中,只有一个include语句:
function doGet() {
return HtmlService.createTemplateFromFile('minigallery')
.evaluate() // evaluate MUST come before setting the NATIVE mode
.setTitle('Business Card Mini Gallery | MAvC Graphics.')
.setSandboxMode(HtmlService.SandboxMode.NATIVE);
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
That code is taken directly from the documentation. 该代码直接来自文档。
filename
is a variable, it can take on any value that is passed to it. filename
是一个变量,它可以采用传递给它的任何值。
You can use HTML with UI Service. 您可以将HTML与UI服务一起使用。 See below link:
见下面的链接:
Google Documentation - Use HTML with UI Service Google文档-通过UI服务使用HTML
But, I don't think you can use both HTML and UI Service together. 但是,我认为您不能同时使用HTML和UI服务。 I can't find anything that states that, but I know I've tried it in the past.
我找不到任何能说明这一点的信息,但是我知道我曾经尝试过。 So, I'm quite sure that you need to decide on one or the other.
因此,我很确定您需要决定一个或另一个。 But if someone knows of a way, I'd sure like to know how.
但是,如果有人知道一种方法,我肯定会知道如何做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.