在EJS上打印原始HTML字符串 [英] Print raw html strings on EJS
本文介绍了在EJS上打印原始HTML字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< %=< a href ='#'>测试< / a> %GT;
但打印出来:
& lt; a href ='#'& gt&Test& lt; / a& gt
如何打印html安全字符串?
解决方案
你应该使用html代码到处,只能在需要动态数据的地方使用EJS标签。示例:
< a href ='<%= user.id%>'><%= user .name%< / a>
要具体回答您的问题,您可以使用<% - < tags_here>中%>
以输出未转义的 HTML数据。
I'm using express.js with EJS templates and i'm trying to do something like this:
<%= "<a href='#'>Test</a>" %>
but it prints this:
<a href='#'>Test</a>
how can i print "html safe" strings?
解决方案
You should use html code everywhere, and use the EJS tags only where you need dynamic data. Example:
<a href='<%= user.id %>'><%= user.name %</a>
To specifically answer your question you can use <%- "<tags_here>" %>
to output unescaped HTML data.
这篇关于在EJS上打印原始HTML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文