[英]Ejs2 include(variable) not working
Ejs2 docs say it is possible to do: Ejs2文档说可以做到:
exports.get = function(req, res) {
res.render('layouts/home', {
page: '../pages/' + 'home'
});
};
and then within the layouts/home.ejs: 然后在layouts / home.ejs中:
<!-- !PAGE CONTENT! -->
<div>
<!-- Sidenav/menu -->
<% include ../partials/sidebar %>
<!-- Content -->
<% include(page) %>
<!-- Footer -->
<% include ../partials/footer %>
</div>
but it writes: 但它写道:
{ [Error: ENOENT: no such file or directory, open 'D:\project\views\layouts\(page).ejs']
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'D:\\project\\views\\layouts\\(page).ejs' }
I installed ejs2. 我安装了ejs2。 But somehow it does not work. 但是以某种方式它不起作用。 Before this ejs1 worked fine. 在此之前,ejs1工作正常。 But i did not have this include(var) functionality. 但是我没有这个include(var)功能。
This may be a little bit late, but I had the same problem and fixed it by changing: 这可能有点晚了,但是我遇到了同样的问题,并通过更改来解决了这个问题:
<% include(var) %>
to 至
<%- include(var) %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.