在玉中使用变量包括 [英] Use a variable in a Jade include
本文介绍了在玉中使用变量包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
app.js
app.get(' / admin',function(req,res){
var Admin = require('./ routes / admin / app')。Admin;
res.render(Admin.view,{
标题:'Admin',
page:'admin'
});
});
layout.jade
- var templates = page +'/ templates /'
包含模板
当我这样做我得到错误 EBADF,坏文件描述符'templates.jade'
我甚至试过
include#{templates}
无效。
解决方案
AFAIK JADE不支持动态包含。我建议的是在模板之外包含,即
app.js
app.get('/ admin',function(req,res){
var Admin = require('./ routes / admin / app'
var page ='admin';
var templates = page +'/ templates /';
//渲染模板并将结果存储在html变量
res.render(templates,function(err,html){
res.render(Admin.view,{
title:'Admin',
page:page ,
html:html
});
});
});
layout.jade
|!{html}
I'm working with Jade and Express and I would like to use a variable in my include statement. For example:
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
When I do this I get the error EBADF, Bad file descriptor 'templates.jade'
I even tried
include #{templates}
to no avail.
解决方案
AFAIK JADE does not support dynamic including. What I suggest is to "include" outside the template, i.e.
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 }
这篇关于在玉中使用变量包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文