koa-views

Template rendering middleware for koa

koa-views

Template rendering middleware for koa.

Supported template engines

$ npm install koa-views
// Must be used before any router is used 
app.use(views('views', {
  map: {
    html: 'underscore'
  }
}));
 
app.use(function* (next) {
  this.state = {
    session: this.session,
    title: 'app'
  };
 
  yield this.render('user', {
    user: 'John'
  });
});

For more examples take a look at the tests

  • root (__dirname): __dirname + where your views are located
  • opts: these options go straight to co-views.
    • root: view root directory

Set the DEBUG environment variable to koa-views when starting your server.

$ DEBUG=koa-views

MIT