I'm getting syntax errors when trying to modularize a Google Apps Script HTML project. The issue appears to be related to how the HTML service processes included files as templates rather than raw content. The code works perfectly when written directly in the main index.html file, but breaks when I try to extract it to separate modules using the recommended include pattern:
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
function doGet() {
return HtmlService.createTemplateFromFile("index").evaluate()
.setTitle("My App")
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
When I create a separate file containing ES6 syntax I get syntax errors like:
Uncaught SyntaxError: Failed to execute 'write' on 'Document': Unexpected token ';'
<?= include('file') ?>
(printing scriptlet) doesn't work.<?!= include('file') ?>
(force-printing scriptlet) doesn't work either.HtmlService.createHtmlOutputFromFile().getContent()
always processes files as templates and not just 'copy-paste' the content.Is there a workaround to include raw file content without template processing?
It seems all I needed to do was to use
getRawContent()
instead of
getContent()
for the scriplet to 'copy-paste' the code instead of solving it before assembling it in the file...
this seems to bypass all the limitations of the scriplet printing.