3

koa で基本的な nunjucks の例を実行しようとしていますが、基本テンプレートを参照すると、見つからないというエラーが発生します

Error: template not found: layout.html

index.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>

render.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')

私が少し興味を持っているもう 1 つのことは、nunjucks ライブラリ リファレンスが渡される場所です。render.js に何らかの形で注入する必要がありますか?

4

0 に答える 0