Split a string into an array using a specified delimiter

How to split a string with a specific format into an array in the Anqi CMS template?

splitThe filter can split a string with a specific format into an array using a specified delimiter.If the delimiter is not present in the string, it will return an array of length 1, with the value being the string itself.If the delimiter is empty, it will split the array by each UTF-8 character.

Also can be usedmake_listTo cut the string quickly into an arraymake_listWill split each character into an array, a letter is a value, a Chinese character is also a value

Usage method

splitHow to use the filter:

{{ obj|split:"拼接符" }}

make_listHow to use the filter:

{{ obj|make_list }}

For example, if you need to concatenatesplits, the, string, 安企CMSPress,Cut into an array, it can be written like this:

{{ "splits, the, string, 安企CMS"|split:", "|stringformat:"%#v" }}
# 显示结果
[]string{"splits", "the", "string", "安企CMS"}

splitThe filter also supports using assignment tags (set) to store judgment results in a variable, such as:

{% set values = "splits, the, string, 安企CMS"|split:", " %}
{% for item in values %}
<span>{{item}}/</span>
{% endfor %}
# 显示结果
splits/ the/ string/ 安企CMS/

Example Demonstration

splitFilter

{{ "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_listFilter

{{ "john doe"|make_list|join:", " }}
{% for char in "john doe"|make_list %}{{ char }}{% endfor %}
# 显示结果
j, o, h, n,  , d, o, e
john doe