user2052052
user2052052

Reputation: 1

HtmlService.createHtmlOutputFromFile can't find file

I am trying to create a Web App with script and publish it to a web site. I am at the very first experimental level where I want the doGet function to execute

HtmlService.createHtmlOutputFromFile('MyPage') 

and I get the "Not Found" error.

MyPage is a simple HTML file that outputs "Hello World". If I change the script to

HtmlService.createHtmlOutput('Hello World')

the code executes just fine when the URL is linked. It appears that the HTML file I created for the doGet function to access and output can't be found although I have saved it and saved a version of the project that includes it. Can anyone give me a hint?

Upvotes: 0

Views: 5928

Answers (3)

ZeroWolfCode
ZeroWolfCode

Reputation: 105

The Google developer page explains this fairly well and gives an example to start: https://developers.google.com/apps-script/guides/html/

In a nutshell: HtmlService.createHtmlOutput('x'): instructs GAS to print "x" to the page.

HtmlService.createHtmlOutputFromFile('0'): instructs GAS to read and print the code inside of 0.html to the page (*note the use of '0' instead of '0.html' as GAS knows you are pointing to a HTML file.) To create the html file inside of GAS, click the top left "file" button and go "new" -> "html".

Upvotes: 0

Corey G
Corey G

Reputation: 7858

It does not need the extension. But it does need to be an HTML file created with File > new Html File.

Upvotes: 2

JSDBroughton
JSDBroughton

Reputation: 4034

HtmlService.createHtmlOutputFromFile('MyPage') needs the .html extension. So HtmlService.createHtmlOutputFromFile('MyPage.html')

Or is it more complicated than that?

Upvotes: -1

Related Questions