In website content management, we often need to handle various data, among which string processing is particularly common.Many times, the strings obtained from databases or user input contain multiple pieces of information, and we need to split them into independent data items for display or further processing.The template engine of AnQiCMS (AnQiCMS) provides us with powerful string processing tools, among whichsplitandmake_listThese filters can help us convert strings to arrays, but they each have unique working methods and application scenarios.Understanding the differences can help us organize and present content more accurately and efficiently.

splitFilter: Split strings by "rule"

Imagine, your article tags, product attributes, or other data are connected by strings such as commas, semicolons, or specific text, like 'SEO optimization, content marketing, Go language development'.If you want to display these tags one by one or to make a count, you need to decompose this string into individual tag items.now,splitThe filter is your helpful assistant.

splitThe essence lies in needing a clear 'delimiter'. This delimiter is like a pair of scissors, telling the system where to 'cut' the string. For example,{{ "SEO优化,内容营销,Go语言开发"|split:"," }}This code, separated by commas, will split the string into["SEO优化", "内容营销", "Go语言开发"]such an array.

Its usage is very intuitive:{{ 你的字符串变量 | split:"你的分隔符" }}You can choose any character or string as a delimiter, such as a space, a vertical line, or a combination like "##".

It should be noted that if your string does not contain the specified delimiter,splitThe filter does not throw an error, but instead returns an array that only contains the original string itself.This is very useful when processing some data items that may not have delimiters.Another interesting feature is, if you set the delimiter to an empty string ("")splitit will very intelligently split each UTF-8 character of the string. But this is notmake_listThe behavior is different when processing Chinese, the details will be explained in the following.

Practical example:Assuming we have a keyword string of an articlekeywords_str = "安企CMS,建站,SEO,Go语言"We want to display these keywords separately.

{% set keywords_str = "安企CMS,建站,SEO,Go语言" %}
{% set keyword_list = keywords_str|split:"," %}
<ul>
{% for kw in keyword_list %}
    <li>{{ kw|trim }}</li> {# 使用trim过滤器去除可能存在的空格 #}
{% endfor %}
</ul>

This code will first separate the string with commas, then traverse the generated array, and display each keyword as a list item.

make_listFilter: The art of breaking down character by character.

withsplitDepending on the delimiter, different,make_listThe filter works in a more direct and pure way: it splits each individual character of the string into an array.It does not care about any separators, as if it picks out each character, each letter, and each symbol from the string separately.

This filter is very suitable for those who need to perform character-level operations on strings.For example, do you want to count how many characters (including Chinese characters) are contained in a string, or do you need to display each character individually to achieve some special effect (such as typewriter effect, text reversal, etc.)?

make_listUsage is more concise:{{ 你的字符串变量 | make_list }}It automatically identifies and processes various characters in the string, whether they are English letters, numbers, or complex Unicode characters (such as Chinese).In AnQi CMS template environment, it handles multibyte characters well, ensuring that each Chinese character is treated as a separate element.

Practical example:Assuming we have a title `title_str = “AnQi CMS, Efficient Content Management`