Skip to main content

Interpolation

Usage

{{= <expression> }}

Examples

Displaying content

Dot Template
{{{
const name = "marcellino ornelas";
}}}
{{= name}}
Result
null

Displaying complex expression

Any valid javascript expression can be used in between the brackets.

Dot Template
{{{
const name = "marcellino ornelas";
}}}
{{= name.startsWith("m") ? `${name[0].toUpperCase()}${name.slice(1)}` : name }}
Result
null

Instance file using template data

You can render data passed into templates into your instances files which then can be used in the instance file itself.

Instance files can take advantage of using template data by rendering the data in a language compatible way.

Take this template that is rendering different types of data types into a .js file. After a instance is created, we can then invoke the js file and it will produce results that were defined in the template.

Dot Template
{{{
const name = "Marcellino ornelas";
const age = 24;
const userInfo = {
name,
age,
};
const users = [userInfo];
}}}
{{{/* Strings should be wrapped in qoutes of choice */}}}
const name = "{{= name}}";
{{{/* Numbers can be rendered to the output */}}}
const age = {{= age}};
{{{
/**
* You can use JSON.stringify to display objects or arrays
* or you can build your own custom function to do something similar
*/
}}}
const userInfo = {{= JSON.stringify(userInfo, undefined, 2)}};
const users = {{= JSON.stringify(users, undefined, 2)}};

console.log(name, age, userInfo, users);
Result
null

Invoking this file with node will now produce the following:

> node path/to/file.js
Marcellino ornelas 24 { name: 'Marcellino ornelas', age: 24 } [ { name: 'Marcellino ornelas', age: 24 } ]