3

我正在尝试使用 koa 做一个基本的 nunjucks 示例,当它引用基本模板时出现未找到错误

Error: template not found: layout.html

索引.html

{% extends "layout.html" %}

{% block body %}
<h1>{{ title }}</h1>
{% endblock %}

布局.html

<!doctype html>
<head>
    <title>simple example</title>
</head>
<body>
<h1>Simple example</h1>
{% block body %}{% endblock %}
</body>

渲染.js

var views = require('co-views');

module.exports = views(__dirname + '/../views', {
    map: { html: 'nunjucks' }
});

服务器.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 中注入它吗?

4

0 回答 0