【问题标题】:How to connect css to html in Google Apps Scripts如何在 Google Apps 脚本中将 css 连接到 html
【发布时间】:2016-09-03 17:21:44
【问题描述】:

我正在尝试制作我的第一个 Google 应用。我有我的 HTML 文档,其中包含 HTML Service: Best Practices 中概述的 include 语句。

<html>
    <head>
        <base target="_top">
        <?!= include('stylesheet') ?>
    </head>
    <body>
       ...
    </body>

我的code.gs文件如下:

function doGet() {
   return HtmlService.createTemplateFromFile('BooksTS2.html')
  .evaluate();
}

我的样式表被命名为 stylesheet.html,并且为了测试目的非常简单:

<style>
   p {color: green;}
</style>

但是当我运行它时,我得到这个错误信息:ReferenceError: "include" is not defined.

【问题讨论】:

    标签: html css google-apps-script


    【解决方案1】:

    在他们创建可重用函数 include() 的示例中,您需要将其添加到您的 code.gs 文件中:

    function include(filename) {
      return HtmlService.createHtmlOutputFromFile(filename)
          .getContent();
    }
    

    您始终可以直接在您的 html 文件中使用打印 scriptlet,如下所示:

    <html>
        <head>
            <base target="_top">
        <?!= HtmlService.createHtmlOutputFromFile('stylesheet').getContent(); ?>
        </head>
        <body>
           ...
        </body>
    </html>
    

    【讨论】:

    • 谢谢!这正是我所需要的。
    猜你喜欢
    • 2021-06-02
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    相关资源
    最近更新 更多