siren-views

Template rendering middleware for koa.

Usage no npm install needed!

<script type="module">
  import sirenViews from 'https://cdn.skypack.dev/siren-views';
</script>

README

siren-views

Build Status

Template rendering middleware for koa, modified from koa-views:

  • instead of ctx.locals, we use ctx.state to store template context.
  • return yield *next if ctx.render exists (no matter what the type is).

Example

var koa = require('koa');
var views = require('siren-views');

var app = koa();

app.use(views('views', {
  default: 'jade',
  map: {
    html: underscore
  }
}));

app.use(function* (next) {
  this.state.session = this.session;
  this.state.title = 'app';

  yield this.render('user', {
    user: 'John'
  });
});

API

Please refer to koa-views.

Tests

Tests use mocha and can be run with npm:

npm test

License

MIT