Rogerio Chaves Rogerio Chaves - 1 year ago 211
Node.js Question

Print raw html strings on EJS

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?

Answer Source

You should use html code everywhere, and use the EJS tags only where you need dynamic data. Example:

<a href='<%= %>'><%= %</a>

To specifically answer your question you can use <%- "<tags_here>" %> to output unescaped HTML data.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download