Thanks for all,
It works for me:
exports.list = function(req, res, next){
dataList.find({}, function(error, users){
var locals = {};
if(error) return next(error);
res.render('index',{users:users,title:'how to render?'});
});
};
Pergunta
I am getting issue to render my data to the html using 'ejs' template engine. Any one can help me please..?
When user goes to app.get('/', userList.list);
I am calling the function:
exports.list = function(req, res, next){
dataList.find({}, function(error, users){ // users consoles correctly.
var locals = {};
if(error) return next(error);
res.render('index', // this is file name. is it wrong?
{ name:name,
dept:dept
}
);
});
};
here is my index.ejs:
<body>
<h1>Please Add your Details</h1>
<% users.forEach(function(user) { %>
<div class="photo">
<h2><%=user.name%></h2>
<p>Department Is : <%= user.dept %></p>
</div>
<% }) %>
</body>
But nothing rendering in the page. what is wrong? any one help me. I am a beginner for this 'ejs' template and node.
Solução
Thanks for all,
It works for me:
exports.list = function(req, res, next){
dataList.find({}, function(error, users){
var locals = {};
if(error) return next(error);
res.render('index',{users:users,title:'how to render?'});
});
};