0
votes

I'm new here (in fact, i'm just starting to learn about coding myself) so I'm sorry if i asked stupid question. I'm trying to learn to code using google Appscript by following tutorial but somehow everything produced an error. here's the code in code.gs:

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

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

both produced an error, the doGet produced SyntaxError: Unexpected token '='

while the include function produced Exception: Bad value

i really don't know where i went wrong, i even copy pasted these from their documentation

edit: fixed the 1st error thanks to the answer, but the second error remains. here's the html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
    <!-- Icon -->
    <link href="https://cdn.lineicons.com/2.0/LineIcons.css" rel="stylesheet">
    <?!=include("page-css"); ?>
  </head>
  <body>
    <h1>Well, Hello There!</h1>
  </body>
</html>

(the 1st error was because i wrote

<?! = include("page-css"); ?> 

instead of

<?!=include("page-css"); ?> 

also, the page-css is still empty,

<style>

</style>

i wrap it in because i can't make .css file in google appscript

Update:

i tried to run the function in the appscript (that play button) and it produce exception : bad value @ line 7 (the return HtmlService line). but when i tried to test deployment, it works the way i expected it to be.

1
I think that in your question, the HTML of page might have the issue. So, can you provide your current HTML of page? - Tanaike
You're right, i didn't know the error could come from the html. i wrote <?! = include instead of <?!=include, fixed that one, thanks. but the second error still remains. - Fitrian Hidayat
Thank you for replying. I'm glad your issue was resolved. About your 2nd issue, I cannot understand it. I apologize for my poor English skill. Can I ask you about the detail of your 2nd issue? - Tanaike
Please only add tags that are relevant to your issue. As far as I can tell, it has nothing to do with PHP or JS (I removed those tags for you) - M. Eriksson
apologize for the wrong tags. i just thought that the include functions was php and the gs as JS - Fitrian Hidayat

1 Answers

0
votes

Based on your comment to Tanaike:

i tried to run the function in the appscript (that play button) and it produce exception : bad value @ line 7 (the return HtmlService line). but when i tried to test deployment, it works the way i expected it to be. I am tempted to just leave the error be.

You are getting this error because, if you run the function include from the script editor, the parameter filename is not defined. Therefore, you are trying to create an HTML output based on an unexisting file, and consequently you get an error:

Throws

Error — if the file wasn't found or the HTML in it is malformed

If you want to test the function on the script editor, you could set a default parameter that matches one of your HTML files:

function include(filename = "page-css") {
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

Reference: