How to convert multi-line text to HTML tags in the Anqi CMS template?
linebreaks
The filter can convert multi-line text into HTML tags, with each line enclosed in HTML tags.<p>
and</p>
If there is a blank line in the middle, use it<br/>
.
Can also be usedlinebreaksbr
to process it. andlinebreaks
The difference is,linebreaksbr
Just replace the newline with<br/>
And no p tags are added at the beginning and end.
Can also be usedlinenumbers
To number each line of multi-line text, the symbol starts from 1. For example,1.
.
How to use
linebreaks
How to use filters:
{{ obj|linebreaks }}
linebreaksbr
How to use filters:
{{ obj|linebreaksbr }}
linenumbers
How to use filters:
{{ obj|linenumbers }}
For example, processing stringsthis is a text\nwith a new line in it
, you can write it like this:
{{ "this is a text\nwith a new line in it"|linebreaks }}
# 显示结果
<p>this is a text<br />with a new line in it</p>
Sample Demo
linebreaks
Filter
{{ ""|linebreaks|safe }}
{{ simple.newline_text|linebreaks|safe }}
{{ simple.long_text|linebreaks|safe }}
{{ "john doe"|linebreaks|safe }}
# 显示结果
<p>this is a text<br />with a new line in it</p>
<p>This is a simple text.</p><p>This too, as a paragraph.<br />Right?</p><p>Yep!</p>
<p>john doe</p>
linebreaksbr
Filter
{{ ""|linebreaksbr|safe }}
{{ simple.newline_text|linebreaksbr|safe }}
{{ simple.long_text|linebreaksbr|safe }}
{{ "john doe"|linebreaksbr|safe }}
# 显示结果
this is a text<br />with a new line in it
This is a simple text.</p><p>This too, as a paragraph.<br />Right?</p><p>Yep!
john doe
linenumbers
Filter
{{ simple.long_text|linebreaksbr }}
# 显示结果
1. This is a simple text.
2. This too, as a paragraph.
3.
4. Right?
5. Yep!