tj / ejs

Embedded JavaScript templates for node
4.47k stars 513 forks source link

Cannot render HTML with EJS template #240

Open blake-edwards opened 6 years ago

blake-edwards commented 6 years ago

Here is the code I am using to render blog posts that will contain HTML. The HTML, as seen in the picture below, is rendered as text even though I used <%- in order to allow HTML. Is there a bug or is there something I am missing here?

   <% for(var i=0; i < result.length; i++) { %>   
              <div class="card">
                  <h2><%= result[i].title %></h2>
                  <h5>Posted: <%= result[i].posted %></h5>
                  <p><%- result[i].body %></p>
              </div>
     <% } %>

Output example:

screen shot 2018-09-15 at 2 36 24 am

If someone could explain to me why this current implementation is not working as expected that would be greatly appreciated!

d4rckh commented 6 years ago

i have the same problem

blake-edwards commented 6 years ago

@ndr3w221 Somehow the EJS template now displays HTML. I changed nothing in my code. Try using
in your text you are trying to display and get back to me. I am very confused but happy it is working!