渲染ejs模板 [英] Rendering ejs template
本文介绍了渲染ejs模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在nodejs中有以下代码(我读取temp.ejs文件并以ejsHtml作为字符串形式获取内容):
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>' } );
在temp.ejs中:
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>
输出:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<body>
<div> smth </div>
</body>
</html>
请告诉我如何获取HTML
Please tell me how to get Html and not that
推荐答案
要输出转义的 html,请执行以下操作:
For outputting escaped html, you do the following:
<%= code %>
要输出未转义的 html,请使用以下
To output unescaped html, you would use the following
<%- code %>
这篇关于渲染ejs模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文