template

A template stores a compiled template string that can be evaluated and rendered on demand using the .render() method. Unlike template strings, which are evaluated immediately, a template instance can be stored as a property and rendered later using the current local variables or a provided context.

A template can be created using the template function.

When a template is returned directly from a query (without calling render), it serializes as its raw template string.

This code creates a template and returns its raw string representation:

template('Hello {name}!');

Return value in JSON format:

"Hello {name}!"

Example

This code creates a template property greeting on the root of a collection and renders it:

.greeting = template('Hello {name}!');
name = 'World';
.greeting.render();

Return value in JSON format:

"Hello World!"

Functions

Function Description
len Return the length of the raw template.
render Renders a template using the current local variables, unless a context thing is provided.