Forum

Thread tagged as: Question

Using the "replace"-tag to convert newline to "br"

Hi,

When I am using the YouTube-fieldtype, and fetching the video-description-field from YouTube, it get's output'ed without formatting.

I want this text:

Bla bla bla
Blue blue blue

Some more blue

To be converted to:

Bla bla bla<br>
Blue blue blue<br>
<br>
Some more blue<br>

I tried using this syntax: replace="\n|<br>" But it does not find anything.

See: https://docs.grabaperch.com/docs/templates/attributes/replace/

What syntax to use?

Svein Are Gronsund

Svein Are Gronsund 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I can't think of a way to do that with the replace attribute. The values are taken as literal, so \n will not be interpreted as a new line character.

I want to show the video-description including the newlines. Can you think of another way to be able to show the description nicely?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Would the white-space property help here?

https://developer.mozilla.org/en/docs/Web/CSS/white-space

Thanks. white-space: pre-line; did the trick :)