【发布时间】:2016-06-26 11:22:09
【问题描述】:
我想在翡翠模板中包含一个 HTML 文件。文件的路径和名称是服务器在用户请求后发送的变量/参数。
index.js 片段
app.get('/material/*', function(req, res){
var lpath = "../static/show/" + req.name; // req.name looks like newSite.html
res.render("newView.jade", {lpath: lpath});
});
newView.jade 的代码
include !{lpath}
但随后浏览器显示
Error: E:\Git\GitHub\chat-example\views\lecture.jade:1
> 1| include !{lpath}
2|
ENOENT: no such file or directory, open 'E:\newSite\views\!{lpath}.jade'
at Error (native)
at Object.fs.openSync (fs.js:584:18)
我测试了 lpath 是否正确。如果我以这种方式添加 lpath i
include ../static/show/newSite.html
一切都很好。我也试过管道(见Use a variable in a Jade include)
|!{lpath}
感谢您的任何想法和提示。
【问题讨论】:
标签: node.js templates variables include pug