Print raw html strings on EJS

一世执手 提交于 2019-12-17 10:52:31

问题


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:

&lt;a href='#'&gt;Test&lt;/a&gt;

how can i print "html safe" strings?


回答1:


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.




回答2:


for raw output html in ejs you can use this code

<%- "<a href='#'>Test</a>" %>


来源:https://stackoverflow.com/questions/8124583/print-raw-html-strings-on-ejs

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