Solution 1 :

This works perfectly for me:

function helpme() {
  var template = HtmlService.createTemplate('<?= foo ?>');
  template.foo = '<h1>Hello World Again!</h1>';
  var html=template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
  SpreadsheetApp.getUi().showSidebar(html);
}

Problem :

I’m using this code from a course on Udemy. When it runs I get this on the side bar in sheets:

<h1>Hello World Again!</h1>

Of course I don’t want the HTML, but I can’t figure out what’s up. Here is the code:

var template = HtmlService.createTemplate('<?= foo ?>');
  template.foo = '<h1>Hello World Again!</h1>';
  Logger.log(template.evaluate().getContent());  // will log 'Hello World!'
  var html = template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
  SpreadsheetApp.getUi().showSidebar(html);

In the video in the course, he doesn’t get it. It works perfectly. I usually type everything in myself, but this is copied from the course.

Comments

Comment posted by stackoverflow.com/q/28459829

I think that this might be your answer.

Comment posted by tonymiceli

Thanks, i will copy your code and see if it works. I’m getting back into all this from the 80s and 90s. (Musician, with obiously no gigs at the present time :-). I type stuff in, match with the course, it’s exact. I run it and it doesn’t work. I replace with the course script and it works. So I’m doing something stupid. I guess i can’t see detail. But thanks, I’ll try your code out. I’m sure it will work!!!!

Comment posted by ale13

Hey there tony, just like @Tanaike mentioned, use

By