Strings are cut into arrays according to the specified delimiter

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

splitThe filter can split strings of a specific format into an array using a specified delimiter.If the delimiter does not exist in the string, it will return an array of length 1, with the value being the string itself.If the delimiter is empty, the array will be split by each utf8 character.

Can also be usedmake_listTo quickly cut strings into arrays.make_listEach character will be split into an array with a value, a letter is one, and a Chinese character is one.

How to use

splitHow to use filters:

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

make_listHow to use filters:

{{ obj|make_list }}

For example, it is necessary tosplits, the, string, 安企CMSaccording to,Cut into an array, you can write this:

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

splitFilters also support use in assignment labels (sets), storing the judgment results into a variable, such as:

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

Sample Demo

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