-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathrender.js
More file actions
24 lines (20 loc) · 779 Bytes
/
render.js
File metadata and controls
24 lines (20 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let Renderer = require('engine/koa/renderer');
// (!) this.render does not assign this.body to the result
// that's because render can be used for different purposes, e.g to send emails
exports.init = function(app) {
app.use(async function(ctx, next) {
let renderer = new Renderer(ctx);
/**
* Render template
* Find the file:
* if locals.useAbsoluteTemplatePath => use templatePath
* else if templatePath starts with / => lookup in locals.basedir
* otherwise => lookup in ctx.templateDir (MW should set it)
* @param templatePath file to find (see the logic above)
* @param locals
* @returns {String}
*/
ctx.render = (templatePath, locals) => renderer.render(templatePath, locals);
await next();
});
};