How to split a line of text into an array in the AnQi CMS template?
fields
Filters can split a line of text into arrays in a template by spaces. The array defined is a[]string{}
, you can traverse the output results in the subsequent process.
How to use
fields
Usage of filters:
{% set values = "文字内容"|fields %}
{% set values = "splits the string 安企CMS"|fields %}
{{values|stringformat:"%#v"}}
# 显示结果
[]string{"splits", "the", "string", "安企CMS"}
Sample Demo
{% set values = "splits the string 安企CMS"|fields %}
{{values|stringformat:"%#v"}}
# 显示格式
[]string{"splits", "the", "string", "安企CMS"}
# 遍历输出
{% for item in values %}
<span>{{item}}</span>/
{% endfor %}
# 显示结果
splits/ the/ string/ 安企CMS/