koa-nunjucks-next
koa2 view render based on nunjucks, support asynchronous filters.
Installation
npm install koa-nunjucks-next
Warn
Do not use babel compile。
API
views(root, opts)
root
: (defaultviews
) Views location. All views yourender()
are relative to this path.opts
nunjucks configure optsopts.globals
: nunjucks global values that will be available to all templatesopts.filters
: nunjucks filters, support asynchronous filteropts.extensions
: nunjucks extensions (e.g. highlight code blocks)
filters: { return { ; }; } asyncAdd2: async { let val3 = await { ; }; return await { ; }; } { return val1 + val2; }
opts.extname
: (defaulthtml
) Extension for your views
// instead of thisawait ctx// you canawait ctx
ctx.render(template, content, [isStringTemplate])
// renders a templateawait ctx // renders a raw stringawait ctx
Example
let views = ; app; router; router; //==> 66667