gpt4 book ai didi

node.js - 在 Jade 包含中使用变量

转载 作者:IT老高 更新时间:2023-10-28 21:52:45 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com