1

I giving a first shot at HTML templating with Google AppsScript and have had a pretty decent experience so far. My problem is that URLs are not being processed (replaced by "false")

My code.gs looks like this :

var section = HtmlService
  .createTemplateFromFile('section')
  .evaluate()
  .setSandboxMode(HtmlService.SandboxMode.IFRAME);

Logger.log(section.getContent());

and my html (section.html) :

<? 
var section = [
  {title: "foo",
   paragraph: "bar",
   url: "https://www.youtube.com/v=foobar"},
  {title: "foo2",
   paragraph: "bar2",
   url: "https://www.youtube.com/v=foobar2"}];

for (var x in section) { ?>

<h1><?= section[x].title ?> </h1>
<p><?= section[x].paragraph ?> </p>
<a href="<?= section[x].url ?>"> link </a>

<? } ?>

And the result of this (the log) :

<h1>foo </h1>
<p>bar</p>
<a href="false"> link </a>

<h1>foo2 </h1>
<p>bar2</p>
<a href="false"> link </a>

The same occurs for img' urls as well so I'm guessing there is a security notion here that I might be overlooking... Do you have an idea how to fix it?

thanks!

1

1 Answer 1

2

Nevermind...

The issue was just improper force-printing syntax...

So if that happens to you in the future, your templating tags should look like this :

<?!= .... =>

and not

<? .... ?>

nor (that was my mistake) :

<?=! .... ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.