mde / ejs

Embedded JavaScript templates -- http://ejs.co
Apache License 2.0
7.72k stars 846 forks source link

EJS template data not rendering on home page #579

Closed KirkM9 closed 3 years ago

KirkM9 commented 3 years ago

I am using ejs, and the data through my ejs template won't load, despite it showing it loads in my node server. This is how I am attempting to bring it in on my index.ejs home page:

<div class= "data">
        <%- include ('template.ejs', { data }); %>   
        </div>

and in my backend (index.js) , this is how I am rendering the data on my home page

res.render('index', {
          data: data
      });

Is there anything wrong with this approach?

jaydave1412 commented 3 years ago

I have some questions are you getting any ejs rendering errors is template.ejs in the same folder as this file(is the path correct)

<%= data %>
<div class= "data">
        <%- include ('template.ejs', { data }); %>   
 </div>

try doing this and see are you getting any value for data if yes try printing the value in the template file

<%# template.ejs %>
<%= data %>
KirkM9 commented 3 years ago

Resolved it myself. Was an issue with my express server