Skip to content

Commit

Permalink
If "renderToResponseBody" set false, the render result will return by…
Browse files Browse the repository at this point in the history
… promise.
  • Loading branch information
徐进 committed Dec 16, 2015
1 parent 50baab1 commit 926bcba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The render function is attached to the Koa context. It is availiable in other mi
```js
yield this.render('home', { username: 'Whatever name' });
```
The render function takes two arguments as defined by [nunjucks.render](http://mozilla.github.io/nunjucks/api.html#render). It does NOT take a callback, but return a promise.
The render function takes two arguments as defined by [nunjucks.render](http://mozilla.github.io/nunjucks/api.html#render). It does NOT take a callback, but return a promise. If "renderToResponseBody" set false, the render result will return by promise.

If you want to make a variable available in all templates, use [koa ctx.state](https://github.com/koajs/koa/blob/master/docs/api/context.md#ctxstate).

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ module.exports = function (templatesPath, nunjucksOptions, extConfig, callback)
if(extConfig.renderToResponseBody === true) {
koaContext.type = extConfig.contentType;
koaContext.body = result;
resolve();
} else {
resolve(result);
}
resolve(result);
}
}, extConfig));
} else {
Expand Down

0 comments on commit 926bcba

Please sign in to comment.