art-async-template
v4.13.4
Published
Clone of art-template with async/await support in templates.
Downloads
1
Readme
art-async-template
This is a fork of original art-template project. It extends functionality by adding async/await calls functions inside templates. For example, if you import in art-template object async function that use I/O, you can use it in template.
const art = require('art-async-template');
art.defaults.imports.doAsync = async function () {
return await asyncProcedure();
};
In template use this:
<%= await $imports.doAsync() %>
Profit! Also, it can be applied with methods of render data
class Test {
i = 0;
async doAsync() {
// some code
}
}
const art = require('art-async-template');
var fn = await art.compile(path.join(__dirname, 'test.art'));
var html = await fn({ test: new Test() });
In template use this:
<% await test.doAsync() %>