koa-modules / swig

Koa view render based on Swig, support tags, filters, and extensions
MIT License
30 stars 12 forks source link

Compatibility with the current koa2 version #19

Open Sharaal opened 8 years ago

Sharaal commented 8 years ago

Hi,

currently the module use the outdated syntax with function*, yield and this.body.

To use the module with the current koa2 version the render function must be co-wrapped, the writeBody set to false and ctx.body manually set:

import co from 'co';
import Koa from 'koa';
import render from 'koa-swig';

const app = new Koa();
app.context.render = co.wrap(render({ writeBody: false }));
app.use(async (ctx) => {
  ctx.body = await ctx.render('index.html.twig');
});
app.listen(process.env.PORT);
microacup commented 8 years ago

You are right!

darethas commented 7 years ago

This worked for me, except with writeBody: true.

writeBody: false would not render the template with locals.

using koa-swig 2.2.1, and koa 2.0.1