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?
EJS is a simple templating language that lets you generate HTML markup with plain JavaScript. No religiousness about how to organize things.
<%= Outputs the value into the template (HTML escaped) <%- Outputs the unescaped value into the template.
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.
for raw output html in ejs you can use this code
<%- "<a href='#'>Test</a>" %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With