Template rendering middleware for koa (using nunjucks).
$ npm install koa-view
var view = require('koa-view');
// Must be used before any router is used
app.use(view(__dirname + '/views'));
app.use(function* (next) {
this.state = {
session: this.session,
title: 'app'
};
yield this.render('user', {
user: 'Coder'
});
});
More examples: tests
root
: (defaultviews
) Views location. All view yourender()
are relative to this path.opts
nunjucks configure optsopts.ext
: (defaulthtml
) Extension for your view
// instead of this
yield this.render('user.html')
// you can
yield this.render('user')
MIT