I'm developing a Google Apps Script and I want to pull the URL parameters into a HTML file. For example, if the user goes to my_domain.com/?hello=test the HTML output should be "Hello test". Here is my code.
index.html
<html>
<body><p>Hello <?= data ?></p></body>
</html>
myCode.gs
function doGet(e) {
var t = HtmlService.createHtmlOutputFromFile('index');
t.data = e.parameter.hello;
return t.evaluate();
}
This results in an error message: "Vous ne pouvez pas ajouter ni modifier de propriétés pour cet objet." (You can not add or modify properties for this object.)
I don't know why. I follow this doc https://developers.google.com/apps-script/html_service They say:
The third way for templates to access data is to add variables to a template directly in a script file, as shown in the example below.
function doGet() {
var t = HtmlService.createTemplateFromFile('myTemplate');
t.data = SpreadsheetApp.openById('SPREADSHEET_KEY_GOES_HERE').getRangeByName('dataRange').getValues();
return t.evaluate();
}
Your code:
var t = HtmlService.create HtmlOutput FromFile('index');
The example you cited:
var t = HtmlService.create Template FromFile('index');
An HtmlOutput can't have variables added to it like you are attempting. A template can - and the result of evaluating it is an HtmlOutput.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With