1

我将 nunjucks2 与 express 和 node 一起使用,将 njk 升级到 2.4.2 后出现此错误:

Template render error: (/home/aien/Web/Test/express/views/error.html)
 Template render error: (/home/aien/Web/Test/express/views/layout.html) [Line 56, Column 20]
 expected block end in block statement
   at Object.exports.prettifyError (/home/aien/Web/Test/express/node_modules/nunjucks/src/lib.js:34:15)
   at /home/aien/Web/Test/express/node_modules/nunjucks/src/environment.js:485:31
   at root [as rootRenderFunc] (eval at <anonymous> (/home/aien/Web/Test/express/node_modules/nunjucks/src/environment.js:564:24), <anonymous>:25:3)
   at Obj.extend.render (/home/aien/Web/Test/express/node_modules/nunjucks/src/environment.js:478:15)
   at /home/aien/Web/Test/express/node_modules/nunjucks/src/environment.js:311:35
   at Obj.extend.getTemplate (/home/aien/Web/Test/express/node_modules/nunjucks/src/environment.js:194:17)
   at Obj.extend.render (/home/aien/Web/Test/express/node_modules/nunjucks/src/environment.js:303:14)
   at NunjucksView.render (/home/aien/Web/Test/express/node_modules/nunjucks/src/environment.js:284:15)
   at tryRender (/home/aien/Web/Test/express/node_modules/express/lib/application.js:639:10)
   at EventEmitter.render (/home/aien/Web/Test/express/node_modules/express/lib/application.js:591:3)

错误和布局是简单的 nunjucks 文件,在这里我发布我的app.js配置:

app.set('views', path.join(__dirname, 'views'));
nunjucks.configure('views', {
  express: app,
  autoescape: true
});

app.set('view engine', 'html');
4

1 回答 1

2

好的,刚刚找到解决方案!!在任何事情之前,只需检查块命名!文档中没有任何关于命名约定的内容,所以我的一个块名称是content-top,我将其更改为contentTop现在它正在工作!

于 2016-05-17T16:17:55.853 回答