我正在使用 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'
我什至尝试过
include #{templates}
无济于事。
最佳答案
AFAIK JADE 不支持动态包含。我的建议是在模板之外“包含”,即
app.js
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
});
});
});
layout.jade
|!{ html }
关于node.js - 在 Jade 包含中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12132978/