qts qts - 2 months ago 6
Javascript Question

Handlbars and HTML

I have a database entry with the following data:

"text": "Paragraph 1\n\nParagraph 2\n\nParagraph 3\n"


However when I render this in
handlebars
as follows:

<div>{{{text}}}</div>


I get:

Paragraph 1 Paragraph 2 Paragraph 3


But I am expecting:

Paragraph 1
Paragraph 2
Paragraph 3


Is anyone able to help explain what is going on?

Answer

You can replace \n with <br> like this:

text.replace(/\n/g, "<br>");
Comments