我试图用koa做一个基本的nunjucks示例,我在引用基本模板时遇到了一个未找到的错误
Error: template not found: layout.html
的index.html
{% extends "layout.html" %}
{% block body %}
<h1>{{ title }}</h1>
{% endblock %}
的layout.html
<!doctype html>
<head>
<title>simple example</title>
</head>
<body>
<h1>Simple example</h1>
{% block body %}{% endblock %}
</body>
render.js
var views = require('co-views');
module.exports = views(__dirname + '/../views', {
map: { html: 'nunjucks' }
});
server.js
const route = require('koa-route');
const parse = require('co-body');
const Koa = require('koa');
const app = new Koa();
var render = require('./lib/render');
app.use(function *(){
this.body = yield render('index.html', {title:'hello title'});
});
app.listen(3000);
console.log('listening on 3000')
另一件我有点好奇的是nunjucks库参考传入的地方?我应该在render.js中以某种方式注入它吗?