How to convert multiple lines of text into html tags in Anqi CMS template?
linebreaks
Filters can convert multiple lines of text into html tags according to line breaks. Each line starts and ends with<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 do not add p tags at the beginning and end.
Can also be usedlinenumbers
To mark each line of multiple lines of text, the symbol starts from 1. like1.
.
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 }} # Show results <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!