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

Lambdas

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

Lambdas are functions passed to the renderer. If you assign a lambda to a section, it will be invoked with the sections content. The result will be used as replacement for the section.

Elements.render(`
	Hello {{#modify}}my{{/modify}} world!
`, {
	modify: content => '<b>'+content.toUpperCase()+'</b>',
});
Hello <b>MY</b> world!

You can also assign predefined functions or even class methods:

class Numbers {
	static format(number) {
		return number + ([, 'st', 'nd', 'rd'][number] || 'th');
	}
}

Elements.render(`
	I am the {{#format}}2{{/format}}.
`, {
	format: Numbers.format,
});

I am the 2nd.

Clone this wiki locally