带有多个样式表的Google Apps脚本js链接

时间:2014-11-22 15:20:51

标签: javascript jquery html css google-apps-script

我是Google Apps Scripts的新手,我正在尝试在我的Google网站中实施spacegallery

我把我的css样式表分开了.js文件在脚本编辑器中写入.html并编写了我的html页面(minigallery.html),现在我正在尝试将它们全部链接到Code.gs部分。以下是我到目前为止使用的示例: https://developers.google.com/apps-script/guides/html/best-practices#separate_html_css_and_javascript

这是我目前在Code.gs中的内容,但是当我运行已发布的版本时,css& js文件似乎没有链接(授予我还没有放入图片)。您可以在此处找到发布的链接:

// 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();
}

` 这是我写得不好的minigallery.html代码链接css& js(第一行和最后一行是最重要的):

    <?!= include('customcss'), ('layoutcss'), ('minigallerycss'); ?>

...//lengthy inner page code

<?!= include('eyejs'), ('jqueryjs'), ('layoutjs'), ('minigalleryjs'), ('utilsjs'); ?>

为了使事情复杂化,我将整个事物从spacegallery重命名为minigallery,但我已经适当地更改了所有文件。

1 个答案:

答案 0 :(得分:0)

您只需要一个名为include的函数。现在你有很多名为&#34; Include&#34;。

的函数

要查找的文件的名称将传递给include函数:

<?!= include('Stylesheet'); ?>

在上面一行中,Stylesheet是从中获取内容的文件的名称。您需要多个脚本,而不是具有多个功能。

minigallery.html

<?!= include('customcss'); ?>
<?!= include('layoutcss'); ?>
<?!= include('minigallerycss'); ?>
<?!= include('eyesjs'); ?>
<?!= include('jqueryjs'); ?>
etc.

在你的.gs文件中,只有一个include语句:

Code.gs

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();
}

该代码直接来自文档。 filename是一个变量,它可以采用传递给它的任何值。

您可以将HTML与UI服务一起使用。见以下链接:

Google Documentation - Use HTML with UI Service

但是,我不认为你可以同时使用HTML和UI服务。我找不到任何说明的东西,但我知道我过去曾经尝试过。所以,我很确定你需要决定其中一个。但如果有人知道某种方式,我肯定想知道如何。