Steven Coco
Steven Coco

Reputation: 562

How To Simply Push A Variable To An HtmlService Template AS Html

I am using:

var template = HtmlService.createTemplateFromFile("MyForm.html");

Which contains a variable:

<?= defaultInnerHtml ?>

And I am trying to assign THIS variable with the content of another HTML file:

template.defaultInnerHtml
    = HtmlService.createHtmlOutputFromFile(
        "MyInnerHtml.html").getContent();

But the contents of MyInnerHtml.html become encoded: the angle brackets are replaced with entities etc. I am trying just to stuff some more Html inside the MyForm.html file before serving that back.

I can't see how to get just the raw contents to show up in place of the variable in the template.

Any help?

Upvotes: 0

Views: 517

Answers (1)

user473305
user473305

Reputation:

To disable this contextual escaping of special characters, change your template so it embeds the value of the variable like this:

<?!= defaultInnerHtml ?>

Note the exclamation mark. This specifies force-printing, which directs the template engine to embed the contents of the variable verbatim.

From Google's documentation:

Contextual escaping is important if your script allows untrusted user input. By contrast, you’ll need to force-print if your scriptlet’s output intentionally contains HTML or scripts that you want to insert exactly as specified.

Upvotes: 1

Related Questions