How to connect css to html in Google Apps Scripts

2019-07-14 05:32发布

I'm trying to make my first Google App. I have my HTML doc which has the include statement as outlined on HTML Service: Best Practices.

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

My code.gs file is as follows:

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

My style sheet is named stylesheet.html, and for testing purposes is really simple:

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

But when I run it I get this error message: ReferenceError: "include" is not defined.

1条回答
▲ chillily
2楼-- · 2019-07-14 06:35

In the example they created the reusable function include(), you need to add it in your code.gs file:

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

You can always use the printing scriptlet directly in your html file like this:

<html>
    <head>
        <base target="_top">
    <?!= HtmlService.createHtmlOutputFromFile('stylesheet').getContent(); ?>
    </head>
    <body>
       ...
    </body>
</html>
查看更多
登录 后发表回答