<ul>
<% for(var i=0; i<items.length; i++){ %>
<li><%= link_to(items[i],'supplies/'+items[i]) %></li>
<% } %>
</ul>
代码是这个样子的,然后出现500错误,在模板编译的时候
link_to is not defined
at eval (eval at (D:\nodejs\test\node_modules\ejs\lib\ejs.js:226:12))
at exports.compile (D:\nodejs\test\node_modules\ejs\lib\ejs.js:228:15)
at Object.exports.render (D:\nodejs\test\node_modules\ejs\lib\ejs.js:266:13)
at View.exports.renderFile [as engine] (D:\nodejs\test\node_modules\ejs\lib\ejs.js:292:22)
at View.render (D:\nodejs\test\node_modules\express\lib\view.js:75:8)
at Function.app.render (D:\nodejs\test\node_modules\express\lib\application.js:504:10)
at ServerResponse.res.render (D:\nodejs\test\node_modules\express\lib\response.js:677:7)
at exports.index (D:\nodejs\test\routes\index.js:7:7)
at callbacks (D:\nodejs\test\node_modules\express\lib\router\index.js:165:11)
at param (D:\nodejs\test\node_modules\express\lib\router\index.js:139:11)
下面这些完全看不懂了,不知道是哪里的问题,ejs引擎是肯定安装了。
反正用任何函数都不行了,还有partial函数
7 回复
npm install express-partials
在app.js里面引用express-partials:
var partials = require('express-partials');
在app.set('view engine', 'ejs');
下面添加
app.use(partials());
3.在需要引用模板的地方调用layout:’模版名称’ 示例
app.get('/list', function(req, res){
res.render('list', {
title: 'List',
items: [1991,'byvoid','express', 'Node.js'],
layout:"list"
});
});