How to split a line of text into an array by spaces in Anqi CMS template?
fields
The filter can split a line of text into an array by spaces in the template. The defined array is a[]string{}
It can be traversed and the results output in subsequent operations.
Usage Instructions
fields
Usage of the filter:
{% set values = "文字内容"|fields %}
{% set values = "splits the string 安企CMS"|fields %}
{{values|stringformat:"%#v"}}
# 显示结果
[]string{"splits", "the", "string", "安企CMS"}
Here is an example demonstration
{% 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/