Split a string into an array by a specified delimiter

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_listto quickly split strings into arrays.make_listEach character will be split into an array, where each letter is a value, and each Chinese character is also a value.

Usage Instructions

splitHow to use the filter:

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

make_listHow to use the filter:

{{ obj|make_list }}

For example, if you need to splitsplits, the, string, 安企CMSPress,then you can write it like this:

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

splitThe 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

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