art-async-template

Clone of art-template with async/await support in templates.

Usage no npm install needed!

<script type="module">
  import artAsyncTemplate from 'https://cdn.skypack.dev/art-async-template';
</script>

README

art-async-template

NPM Version NPM Downloads Node.js Version

English document | 中文文档

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() %>