【发布时间】:2014-01-30 03:10:10
【问题描述】:
我在几个地方使用了一个全局标头,我试图在渲染模板时可以传递的变量中定义它的位置。
类似:
var headerLocation = 'some/location/header.ejs';
res.render( viewDir + '/index', {
header: headerLocation
} );
在模板文件中:
<% include header %>
header 是通过渲染传入的值。
这似乎不可能,但也许我错过了一些东西,所以想在这里问。
编辑:
cmets 在下面的答案中提到了这一点,但总而言之,这现在在 EJS 的第 2 版中可用。
请看这里:https://github.com/mde/ejs#includes 以及相关讨论在这里:https://github.com/tj/ejs/issues/93
【问题讨论】: