0

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.

Marios
  • 26,333
  • 8
  • 32
  • 52
  • 3
    I think that this might be your answer. https://stackoverflow.com/q/28459829 In your case, please modify `= foo ?>` to `!= foo ?>` and test it again. – Tanaike Jul 03 '20 at 22:53

1 Answers1

0

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);
}
Cooper
  • 59,616
  • 6
  • 23
  • 54
  • 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!!!! – tonymiceli Jul 04 '20 at 18:10
  • 1
    Hey there tony, just like @Tanaike mentioned, use `!= foo ?>` instead of `= foo ?>`. – ale13 Jul 06 '20 at 09:06