linebreaks Filter

Coding

Documentation

Replaces single newline characters with <br> tags and wraps lines of text separated by two newline characters in <p> tags.

Variable

poem = '''Much to his Mum and Dad’s dismay,
Horace ate himself one day.

He didn’t stop to say his grace,
He just sat down and ate his face.

“We can’t have this!” His Dad declared,
“If that lad’s ate, he should be shared.”'''

Template

{{ poem|linebreaks }}

Result

<p>Much to his Mum and Dad’s dismay,<br>Horace ate himself one day.</p>
<p>He didn’t stop to say his grace,<br>He just sat down and ate his face.</p>
<p>“We can’t have this!” His Dad declared,<br>“If that lad’s ate, he should be shared.”</p>

Did we get something wrong? Is there a use case for the linebreaks filter that we should add? Please let us know.

Send Feedback

Official Documentation
This page last updated on Sept. 16, 2020, 7:34 p.m. EST