Anthony Lockett
Anthony Lockett

Reputation: 51

HTML inside of EJS is not rendered

I have been following several tutorials and for some reason my HTML will not render inside of the EJS.

Here is an example

<% User.find().exec(function(err, users) { %>
<% _.each(users, function(user) { %>
 <p>Test</p>
<% }) %>
<% }) %>

Test will never show up on the page. Anyone know why this is?

My plan is to render some tabular data with users.

Upvotes: 1

Views: 148

Answers (1)

Bruno
Bruno

Reputation: 904

I think one correct way to get some users out of the database and to show them would be to fetch the data inside an action and the send the data with the render method.

Controller

module.exports = {
  showUser: function(req,res){
     User.find({}).exec(function(err, users){
       if(err) return res.negotiate(err);

       return res.view("path/to/view", users);
     });
  }
};

View

<tr>
<% for(var i=0; i<users.length; i++) {%>
   <td><%= users[i] %></td>
<% } %>
</tr>

Upvotes: 2

Related Questions