2

I have a "notes" field in my CartoDB table, that I tried to populate with multi-line texts, but there doesn't seem to be a way to add line breaks. If I use <br /> I just end up with a literal <br /> in my info window.

Can I force a line break?

  • 1
    Found it: stackoverflow.com/questions/21251638/… – Amanda Apr 22 '14 at 3:38
  • 1
    It would be helpful to include the solution you found as an answer for future readers. The link in addition to a description of the solution would be helpful. – Aaron Mar 26 '15 at 11:31
  • What was your solution please? – tommy.carstensen Oct 15 '15 at 18:29
0

From https://stackoverflow.com/questions/21251638/mustache-js-allow-only-line-breaks-escape-other-html

Option 1 - Use a pre tag:

It's actually best (or efficient) that you wrap text in a <pre></pre> tag, which will preserve the white space in the text.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre

And enable word-wrap

https://stackoverflow.com/questions/248011/how-do-i-wrap-text-in-a-pre-tag - http://jsfiddle.net/X5ZY7/


Option 2 - Split your string into lines, and use a mustache each:

comment = userComment.split("\n")


{{#comment}}
    {{comment}}<br/>
{{/comment}}


Option 3 - Manually escape your string using your favorite method before injecting the
tags:

var div = document.createElement("div")
div.textContent = comment
comment = div.innerHTML.replace(/\n/g, "<br/>")


{{{comment}}}
  • Which of these 3 options did you actually use in cartodb? – raphael Mar 29 '16 at 21:44
0

You can keep the <br> tags inside the notes column and signal to mustache.js not to strip the html in that column by using a "triple mustache" around that column in the custom html pane for your info-window: {{{notes}}}

source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.