Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
470 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...