I am trying to print a newline and per the Dust.js guide, in the template I have a {~n} at the end of each record output
{#friends} {name}, {age}{~n}{/friends}
I compiled the above template and am rendering with a couple of JSON records to generate 'out' object. I am using the document.getElementById('divID').innerHTML to replace the 'out' object dynamically in a basic DIV tag. The problem is am not able to print newline inspite of the {~n}. I have also tried {~r}, but still not luck. Any thoughts?
HTML collapses adjacent whitespace (including newline characters) into a single space by default. There is no difference between a word and a \n word (or a \r word or a \r\n word for that matter) by default for most elements. The solution is either to:
<br> element to add the breakwhitespace: pre;Alternately, you can use a list (which is probably more semantic for your use case and should be preferred).
If you're rendering as HTML, you need to use a <br> tag instead of a newline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With