Reputation: 26324
I am passing a text with line break to mustache but while rendering the line breaks are not shown. Please let me know , how to add line breaks in the text.
var test ="test1"+"\n"+"test2"+"\n"+"test3".
I am passing this to Mustache for rendering and expecting this should get printed like
test1
test2
test3
But the actual result is test1test2test3
while rendering this.
Thanks.
Upvotes: 8
Views: 14995
Reputation: 954
white-space: pre-wrap
, NOT white-space: pre
(won't transfer a long string otherwise)
Upvotes: 5
Reputation: 44969
The best approach, in my opinion, is to apply the following CSS to the element you want to show with line breaks:
white-space: pre;
That way, all the \n
will actually show as line breaks. There are also other ways of handling this, for example see Mustache.js allow only line breaks, escape other HTML.
Upvotes: 5
Reputation: 6538
You should use <br>
but in your mustache template you must use {{{myString}}}
to escape html
Upvotes: 14