How to split a string with a specific format into an array using a specified delimiter in the Anqi CMS template?
split
It can also be usedmake_list
to quickly split strings into arrays.make_list
Each character will be split into an array, where each letter is a value, and each Chinese character is also a value.
Usage Instructions
split
How to use the filter:
{{ obj|split:"拼接符" }}
make_list
How to use the filter:
{{ obj|make_list }}
For example, if you need to splitsplits, the, string, 安企CMS
Press,
then you can write it like this:
{{ "splits, the, string, 安企CMS"|split:", "|stringformat:"%#v" }}
# 显示结果
[]string{"splits", "the", "string", "安企CMS"}
split
The filter also supports using it in assignment tags (set), storing the judgment result in a variable, such as:
{% set values = "splits, the, string, 安企CMS"|split:", " %}
{% for item in values %}
<span>{{item}}/</span>
{% endfor %}
# 显示结果
splits/ the/ string/ 安企CMS/
Here is an example demonstration
split
Filter
{{ "splits, the, string, 安企CMS"|split:", " }}
{{values|stringformat:"%#v"}}
# 显示结果
[]string{"splits", "the", "string", "安企CMS"}
{{ "Hello, 99, 3.140000, good"|split:", "|join:", " }}
# 显示结果
Hello, 99, 3.140000, good
make_list
Filter
{{ "john doe"|make_list|join:", " }}
{% for char in "john doe"|make_list %}{{ char }}{% endfor %}
# 显示结果
j, o, h, n, , d, o, e
john doe