Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apps Script Sidebar Reference Error When Using Include

I created a Google Apps Script add-on to display a sidebar on click:

function displayPage_() {
  getScriptProperties_()
  var htmlTemplate = HtmlService.createTemplateFromFile('PAGE');
  var html = htmlTemplate.evaluate()
          .setTitle('Connector');
  SpreadsheetApp.getUi().showSidebar(html);
}   

This successfully loads the file PAGE.html as long as it is simple html. However, when I try to add include like this:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <?!= include("STYLESHEET"); ?>
  </head>
  <body>
  </body>
</html>

It throws this error:

[17-02-09 08:55:50:239 MST] Execution failed: ReferenceError: "include" is not defined.

It doesn't matter what is in the include it always fails.

I have done this before and it worked. As far as I can tell, I have this set up just like the other project, but it doesn't work in this project. I assume that I forgot to enable something, but don't know how to tell what is missing because the transcript is vague.

What am I missing? Or, doing wrong?

like image 956
davids Avatar asked Feb 09 '17 16:02

davids


1 Answers

I got crazy too... Found it in an example provided in Google Script Reference, what I didn't know was that include() is a user-defined function. Paste this code and it will work:

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

Let me know if I understood properly.

like image 117
k4k4sh1 Avatar answered Sep 24 '22 19:09

k4k4sh1