Rendering an ejs template

I have the following code in nodejs (I read the temp.ejs file and get the contents as ejsHtml as a string):

var html = EJS.render(ejsHtml, { A: '<div>smth</div>' } );

And in temp.ejs:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title></title>
</head>
<body>
      <%= A %>
</body>
</html>

Conclusion:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title></title>
</head>
<body>
      &lt;div&gt; smth &lt;/div&gt;
</body>
</html>

Please tell me how to get Html, not

+5
source share
2 answers

To output escaped html, you do the following:

<%= code %>

To output unescaped html you should use the following

<%- code %>
+19
source

I used the underscore to help me. Only <%=or <%-not working.

<%- _.unescape( data.textWithHtml ) %>
+1
source

All Articles