Skip to content

Template rendering middleware for koa (using nunjucks).

Notifications You must be signed in to change notification settings

d-band/koa-view

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-view

NPM version Dependency Status Build Status Coverage Status Greenkeeper badge

Template rendering middleware for koa (using nunjucks).

Installation

$ npm install koa-view
const view = require('koa-view');

// Must be used before any router is used
app.use(view(__dirname + '/views'));

app.use(async function (ctx) {
  ctx.state = {
    session: ctx.session,
    title: 'app'
  };

  await ctx.render('user', {
    user: 'Coder'
  });
});

More examples: tests

API

view(root, opts)

  • root: (default views) Views location. All view you render() are relative to this path.
  • opts nunjucks configure opts
  • opts.ext: (default html) Extension for your view
// instead of this
await ctx.render('user.html')
// you can
await ctx.render('user')

Koa 1 Support

To use koa-view with koa@1, please use koa-view 1.x.

npm install koa-view@1 --save

License

MIT

About

Template rendering middleware for koa (using nunjucks).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published