Rendering ejs template

懵懂的女人 提交于 2019-12-07 03:24:14

问题


I have following code in nodejs (I read temp.ejs file and get content as ejsHtml as 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>

Output:

<!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 and not that


回答1:


For outputting escaped html, you do the following:

<%= code %>

To output unescaped html, you would use the following

<%- code %>



回答2:


I used underscore to help me out. Only <%= or <%- did not work.

<%- _.unescape( data.textWithHtml ) %>


来源:https://stackoverflow.com/questions/10356224/rendering-ejs-template

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!