Newly Paranoid Maintainers

koajs-nunjucks

1.0.1 • Public • Published

Koa.js Nunjucks

NPM Version Node Version License

Installation

$ npm install koajs-nunjucks

Middleware Setup

First, require koajs-nunjucks. It returns a function that will return a middleware generator.

var KoajsNunjucks = require('koajs-nunjucks');
var fMiddleware = KoajsNunjucks('', {});

The function takes two arguments. They are passed in the same order to the nunjucks.configure() function. Next, "use" the middleware function (before any other middleware that attempts to use it).

var app = require('koa')();
app.use( fMiddleware );

Usage

The render function is attached to the Koa context. It is availiable in other middleware functions directly as "this". The function renders the view and automatically sets it as the response body.

yield this.render('home.nj', { username: 'Bob' });

The render function takes two arguments as defined by nunjucks.render. It does NOT take a callback.

In additon to the render function, the enviorment is also attached to the context. Every request creates a fresh enviorment.

this.nunjucks

License

MIT

install

npm i koajs-nunjucks

Downloadsweekly downloads

16

version

1.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability