How do I include a file in HTML Google Apps Script?
In your situation, if <?!=include('Stylesheet'); ?>
is included in index.html
file, how about the following modification?
From:
function doGet() {
return HtmlService.createHtmlOutputFromFile('index');
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).evaluate().getContent();
}
To:
function doGet() {
return HtmlService.createTemplateFromFile('index').evaluate();
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
Note:
-
If
filename
ofinclude(filename)
has the scriptlets, please modify as follows.function include(filename) { return HtmlService.createTemplateFromFile(filename).evaluate().getContent(); }
-
In your script, it seems that Web Apps is used. In this case, when you modified the Google Apps Script, please modify the deployment as a new version. By this, the modified script is reflected in Web Apps. Please be careful this.
-
You can see the detail of this in the report of "Redeploying Web Apps without Changing URL of Web Apps for new IDE".
References:
- createTemplateFromFile(filename)
- createHtmlOutputFromFile(filename)