HtmlTemplate

A template object for dynamically constructing HTML. For more information, see the [guide to templates](https://developers.google.com/apps-script/guides/html/templates).

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/html/html-template#evaluate()` | `https://developers.google.com/apps-script/reference/html/html-output` | Evaluates this template and returns an `https://developers.google.com/apps-script/reference/html/html-output` object. |
| `https://developers.google.com/apps-script/reference/html/html-template#getCode()` | `String` | Generates a string of JavaScript code, based on the template file, that can be evaluated. |
| `https://developers.google.com/apps-script/reference/html/html-template#getCodeWithComments()` | `String` | Generates a string of JavaScript code that can be evaluated, with each line of the code containing the original line from the template as a comment. |
| `https://developers.google.com/apps-script/reference/html/html-template#getRawContent()` | `String` | Returns the unprocessed content of this template. |

## Detailed documentation

### `evaluate()`

Evaluates this template and returns an `https://developers.google.com/apps-script/reference/html/html-output` object. Any properties set on this
`HtmlTemplate` object are in scope when evaluating. To debug errors in a template,
examine the code using the `https://developers.google.com/apps-script/reference/html/html-template#getCode()` method.

```javascript
// A template which evaluates to whatever is bound to 'foo'.
const template = HtmlService.createTemplate('<?= foo ?>');
template.foo = 'Hello World!';
Logger.log(template.evaluate().getContent());  // logs 'Hello World!'
```

#### Return


`https://developers.google.com/apps-script/reference/html/html-output` --- An HtmlOutput object.

*** ** * ** ***

### `getCode()`

Generates a string of JavaScript code, based on the template file, that can be evaluated. This
method produces a string of JavaScript code based on the template file. Calling `
eval(<code>)` returns a new `https://developers.google.com/apps-script/reference/html/html-output` object with the content of the
template after running all embedded server scripts. The generated code is intended to be
human-readable, and so if you need to debug a template you can call `
Logger.log(<code>)` to see what was produced.

Evaluating this code implicitly binds in all variables in the current scope. In general,
it's preferable to use the `https://developers.google.com/apps-script/reference/html/html-template#evaluate()` method, which takes explicit bindings.

```javascript
const template = HtmlService.createTemplate(
    '<b>The time is &lt;?= new Date() ?&gt;</b>',
);
Logger.log(template.getCode());
```

#### Return


`String` --- A string based on the template, which can be evaluated.

*** ** * ** ***

### `getCodeWithComments()`

Generates a string of JavaScript code that can be evaluated, with each line of the code
containing the original line from the template as a comment. This method produces a string of
JavaScript code based on the template file. Calling `eval(<code>)` returns a
new `https://developers.google.com/apps-script/reference/html/html-output` object with the content of the template after running all embedded
server scripts. The generated code is intended to be human-readable, and so if you need to
debug a template you can call `Logger.log(<code>)` to see what was produced.

Evaluating this code implicitly binds in all variables in the current scope. In general,
it's preferable to use the `https://developers.google.com/apps-script/reference/html/html-template#evaluate()` method, which takes explicit bindings.

```javascript
const template = HtmlService.createTemplate(
    '<b>The time is &lt;?= new Date() ?&gt;</b>',
);
Logger.log(template.getCodeWithComments());
```

#### Return


`String` --- A string based on the template, which can be evaluated.

*** ** * ** ***

### `getRawContent()`

Returns the unprocessed content of this template.

```javascript
const template = HtmlService.createTemplate(
    '<b>The time is &lt;?= new Date() ?&gt;</b>',
);
Logger.log(template.getRawContent());
```

#### Return


`String` --- The template's raw content.