Forked from koa-swig, but the usage is a little difference. That is render(app, {});
app.use(render());
Koa view render based on Swig, support tags, filters, and extensions.
npm install koa-swig-render
- First, automatically merge
ctx.state
from koa 0.14. - Second, automatically merge
ctx.flash
. - Finally, merge custom locals.
var koa = require('koa');
var render = require('koa-swig');
var app = koa();
app.use(render({
root: path.join(__dirname, 'views'),
autoescape: true,
cache: 'memory', // disable, set to false
ext: 'html',
locals: locals,
filters: filters,
tags: tags,
extensions: extensions
}));
app.use(function *() {
yield* this.render('index');
});
app.listen(2333);
-
- autoescape
- cache
- locals
- varControls
-
filters: swig custom filters
-
tags: swig custom tags
-
extensions: add extensions for custom tags
-
ext: default view extname
-
root: view root directory
-
writeBody: default(true) auto write body and response
- swig-extras A collection of handy tags, filters, and extensions for Swig.
MIT