koa-middleware-swig
v1.0.4
Published
Koa view render middleware based on Swig, supports tags, filters, and extensions. Forked form github.com/koa-modules/swig
Downloads
6
Maintainers
Readme
koa-middleware-swig
Koa view render middleware based on Swig, support tags, filters, and extensions. Forked form github.com/koa-modules/swig
Usage
Koa v1.x
const swig = require('koa-middleware-swig'); app.use(swig(settings));
Install
npm install koa-middleware-swig
Features
- Use separate swig instance.
Example
var koa = require('koa');
var swig = require('koa-middleware-swig');
var app = koa();
app.use(swig({
views: 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 *() {
//can still access swig object by this.swig
this.body = yield this.render('index');
});
app.listen(2333);
Settings
- autoescape
- cache
- locals
- varControls
- tagControls
- cmtControls
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
Others
- swig-extras A collection of handy tags, filters, and extensions for Swig.
Licences
MIT