简体   繁体   English

在应用程序脚本中分离 html 文件

[英]Separating html file in apps script

I have an apps script file where I want to separate my html and css.我有一个应用程序脚本文件,我想在其中分离我的 html 和 css。 Given we can't create .css files in apps script, I have create a file 'mainmenucss.html' and put my css in a style tag, and using the include function (see below) to add that file in, but none of my styling is showing when I do that.鉴于我们无法在应用程序脚本中创建 .css 文件,我创建了一个文件“mainmenucss.html”并将我的 css 放在样式标记中,并使用包含函数(见下文)添加该文件,但没有当我这样做时,我的造型就会显示出来。

index.html索引.html

<!DOCTYPE html>
<html>
  <head>

    <?!= include('mainmenucss.html') ?> 
  </head>

code.gs代码.gs

function doGet(request) {
   return HtmlService.createTemplateFromFile('mainmenu')
      .evaluate();
}

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

mainmenucss.html主菜单.html

    <style>

      /*-- Text you have "X" emails left --*/
      div {
        display: block;
      }

      body {
        font: normal 10pt Arial, sans-serif;
      }
</style>

How about this modification?这个改装怎么样?

I think that in your script, an error might occur at return HtmlService.createTemplateFromFile(filename).getContent();我认为在您的脚本中, return HtmlService.createTemplateFromFile(filename).getContent();可能会发生错误return HtmlService.createTemplateFromFile(filename).getContent(); . . Because HtmlTemplate has no method of getContent() .因为 HtmlTemplate 没有getContent()方法。 So how about the following modification?那么下面的修改呢?

From:从:

return HtmlService.createTemplateFromFile(filename).getContent();

To:到:

return HtmlService.createTemplateFromFile(filename).evaluate().getContent();

or或者

To:到:

return HtmlService.createHtmlOutputFromFile(filename).getContent();

Note:笔记:

  • If above modification didn't resolve your issue, can you provide the script of mainmenucss.html ?如果上述修改没有解决您的问题,您能否提供mainmenucss.html的脚本?
  • If you are using Web Apps, when you modified the script, please redeploy Web Apps as new version.如果您使用的是 Web Apps,当您修改脚本时,请将 Web Apps 重新部署为新版本。 By this, the latest script reflects to Web Apps.通过这种方式,最新的脚本反映到 Web Apps。

References:参考:

If I misunderstood your question and this was not the result you want, I apologize.如果我误解了您的问题并且这不是您想要的结果,我深表歉意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM