我正在使用Jade和Express,我想在我的include语句中使用一个变量。例如:
app.js
app.get('/admin', function (req, res) { var Admin = require('./routes/admin/app').Admin; res.render(Admin.view, { title: 'Admin', page: 'admin' }); });
layout.jade
- var templates = page + '/templates/' include templates
当我这样做时,我得到了错误 EBADF, Bad file descriptor 'templates.jade'
EBADF, Bad file descriptor 'templates.jade'
我什至试过
include #{templates}
无济于事。
AFAIK JADE不支持动态包含。我建议在模板之外“包含”,即
app.get('/admin', function (req, res) { var Admin = require('./routes/admin/app').Admin; var page = 'admin'; var templates = page + '/templates/'; // render template and store the result in html variable res.render(templates, function(err, html) { res.render(Admin.view, { title: 'Admin', page: page, html: html }); }); });
|!{ html }