chopz
chopz

Reputation: 381

Passing variable to HTML output and then into a scriptlet

Code.gs

function doPost(e) {
    ...
    template.data += getCustomerData + "<br>";
}
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);

index.html

...
<?= data ?>

The code shown does display the correct values. However, it doesn't translate <br> into HTML. I'm not sure why it isn't working since template.evaluate() is supposed to return an HtmlOutput object.

Upvotes: 1

Views: 2522

Answers (1)

Cameron Roberts
Cameron Roberts

Reputation: 7367

By default the strings are sanitized, converting special characters to their HTML encoded equivalents (such as < becoming &lt;).

When outputting HTML you must use <?!= to avoid sanitizing the data.

<?!= data ?>

See the details on standard & force-printing scriptlets here: https://developers.google.com/apps-script/guides/html/templates#standard_scriptlets

Upvotes: 8

Related Questions