问题获取Node.js Express 3.x模板inheritance与Swig通过consolidate.js

我可以得到'独立'的模板来渲染这个代码很好,但我不能让模板inheritance工作。 有什么我可以忽略的或任何其他的警告任何人知道?

错误:在“… /views/index.html”的第3行find循环扩展!

app.js:

var express = require('express') , cons = require('consolidate') , http = require('http') var app = express(); app.engine('html', cons.swig); app.set('view engine', 'html'); app.set('views', __dirname + '/views'); app.set('view options', { layout: false }); app.get('/', function(req, res){ res.render('index.html', { header: 'Express' }); }); http.createServer(app).listen(3000, function(){ console.log("Express server listening on port 3000"); }); 

的index.html

 {% extends 'base.html' %} {% block content %}<h1>{{ header }}</h1>{% endblock %} 

base.html文件

 <!DOCTYPE html> <html> <head> <title>{% block title %}Express{% endblock %}</title> </head> <body> {% block content %}{% endblock %} </body> </html> 

你可以通过为swig自身设置rootallowErrors来解决这个问题:

 var express = require('express') , cons = require('consolidate') , http = require('http') , swig = require('swig') swig.init({ root: __dirname + '/views', allowErrors: true }); // ... 

有关更多信息,请参阅将swig与express.js和Swig API结合使用 。

我不确定swig,但在express3中,他们删除了模板inheritance,部分和布局,并将其留给模板引擎来实现。 有插件可能会为你回来。

ejs: https : //github.com/RandomEtc/ejs-locals

https://github.com/publicclass/express-partials