1

I am trying to make my site more component based using includes in my application but it just throws an error to the page when I reload it. I have tried:

<%=include _partials/site-head/site-head %>

And I have tried:

<%=include virtual="_partials/site-head/site-head" %>

Here is the code.

<%=include virtual="_partials/site-head/site-head" %>

    <h1><%= title %></h1>
    <% for(var i=0; i<userlist.length; i++) {%>
       <p><%= userlist[i].name %></p>
    <% } %>

<%=include virtual="_partials/site-foot/site-foot" %>
MattClaff
  • 685
  • 2
  • 9
  • 17

2 Answers2

1

Tag <%= is used to output variables, for code need to use <%- %>. So to include views you need to write like this:

<%- include _partials/site-head/site-head.ejs %>

    <h1><%= title %></h1>
    <% for(var i=0; i<userlist.length; i++) {%>
       <p><%= userlist[i].name %></p>
    <% } %>

<%- include _partials/site-head/site-foot.ejs %>

Also read this answer.

Community
  • 1
  • 1
vanadium23
  • 3,516
  • 15
  • 27
0

My Answer that solved this was to check what version of express your using, I was using an old version which didnt like include.

MattClaff
  • 685
  • 2
  • 9
  • 17