Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display variable content with html tags in EJS

I just started using a text editor on my page and I'm saving the data in mongoDB, so the data will contain html tags and It'll looks something like this <b>test</b>

I'm using basicaly bootstrap for my front-end, and I'd like to show the information of that variable in my html page.

if I display something like this:

js:

 event.information = '<b>test</b>'

.html or .ejs:

<p><%= event.information %></p>

Current view:

It's showing the data with the html tags e not the actual "effect" of the tag

<b>test</b>

View (that I want):

test

I just want to the page render my <%= event.information %> correctly and using the html tags to format the content and not display the html tags.

like image 498
Johnny Santana Avatar asked Jul 10 '26 10:07

Johnny Santana


1 Answers

Use

<p><%- event.information %></p>

instead of

<p><%= event.information %></p>

inside of your ejs file

<%- Outputs the unescaped value into the template.

like image 177
SemperFi Avatar answered Jul 11 '26 23:07

SemperFi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!