i69chess chess
i69chess chess

Reputation: 31

Printing newline characters in ejs

I'd like to print a string with newline characters with ejs.

I have this ejs file:

<div class="result">
  <%=names%>
</div>

If the string "names" is "line 1</br>line 2" it will print it literally:

line 1</br>line 2

But I'd like this:

line 1
line 2

What is the best way of getting ejs to correctly interpret newline characters?

Upvotes: 2

Views: 740

Answers (1)

i69chess chess
i69chess chess

Reputation: 31

The ejs syntax I was using is specifically for unescaped input:

<div class="result">
  <%=names%>
</div>

Simply using '-' instead of '=' gives the desired result:

<div class="result">
  <%-names%>
</div>

Which gives:

line 1
line 2

Kudos @Pavan Kumar T S

Upvotes: 3

Related Questions