I have used createTemplateFromFile
many time in the past. It lets me use an include method so that CSS and JavaScript can be broken out into a different file. But today I can't seem to make it work. Below is my test code bound to a spreadsheet. Any ideas why its not working? I tried another existing spreadsheet with a custom dialog using the technique and it works.
Code.gs
function onOpen() {
var ui = SpreadsheetApp.getUi();
var menu = ui.createMenu("Test");
menu.addItem("Test", "test");
menu.addToUi();
}
function test() {
try {
var html = HtmlService.createTemplateFromFile("HTML_Test");
Logger.log(html);
// was html.evaluate();
html = html.evaluate(); // correction
SpreadsheetApp.getUi().showSidebar(html);
}
catch(err) {
Logger.log(err);
}
}
HTML_Test:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<select>
<option value="Doc1">Document 1</option>
<option value="Doc2">Document 2</option>
<option value="Doc3">Document 3</option>
</select>
</body>
</html>
Log
[19-01-24 09:54:51:240 PST] {}
[19-01-24 09:54:51:246 PST] Exception: Invalid argument: userInterface
I've been tweeking this every which way to figure out why it wouldn't work. You get blind to a simple solution. html = html.evaluate()
works.
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