qts qts - 1 year ago 84
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
as follows:


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 Source

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

text.replace(/\n/g, "<br>");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download