Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Data Types

Lukas Jans edited this page Feb 21, 2019 · 1 revision

Instead of passing an object with properties to the renderer, you can also use other types of data.

Scalars

If you pass a scalar directly to the renderer, it can only be referenced using the local context:

Elements.render('A {{.}} C', 'B');

A B C

Arrays

When an array is passed directly to the renderer, the whole template will be repeated and rendered for each item in the array. Like usual, the items can be scalars or other types of data.

Elements.render('<a href="#{{.}}">{{.}}</a>', ['top', 'bottom']);
<a href="#top">top</a>
<a href="#bottom">bottom</a>

Classes

Class instances behave like objects, so they can also be used for rendering:

class Test {
	get value() { return 'world'; }
	alter(text) { return text.toUpperCase(); }
}

Elements.render('{{#alter}}Hello{{/alter}} {{value}}!', new Test());

HELLO world!

Clone this wiki locally