1

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.

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

1 Comment

This does set the data, however, it is limited in that the data needs to be formatted previously (unless its something simple like a string or number). For a more comprehensive way to pass a server variable to the client html, see this answer: I made an answer regarding this here: stackoverflow.com/a/38314034/2213940

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.