What is the difference between the `split` filter and the `make_list` filter in terms of string splitting into arrays?

Calendar 👁️ 65

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`

Related articles

How to use the `split` filter in the `{% set %}` tag to assign the sliced array to a new variable?

In AnQiCMS template development, flexibly handling and displaying data is the key to enhancing the expression of website content.We often encounter such a scenario: from the background, we get a string containing multiple pieces of information, such as keywords of articles, product feature lists, which may be separated by commas or other symbols.If it is possible to split these strings into independent segments and display or process each segment separately, it can greatly increase the flexibility of the template and the dynamism of the content.

2025-11-08

What should be noted about character encoding when using the `split` filter to cut Chinese, English, or mixed Chinese and English and numeric strings?

In AnQi CMS template development, the `split` filter is a very practical tool that helps us break down complex string data into arrays that are easier to handle.When faced with a string containing a mix of Chinese, English, and numbers, how can we ensure that the `split` filter works correctly, especially in terms of character encoding, which is a concern for many users. ### Overview of `split` filter's working principle The `split` filter is mainly used to split a string into an array according to a specified delimiter. For example

2025-11-08

How to iterate and display array elements in a template after splitting a string with the `split` filter?

In the flexible template system of AnQiCMS, we often encounter scenarios where we need to handle specific format strings.For example, an article may have multiple keywords separated by commas, or a custom data segment may be concatenated with some symbols.If we want to display these strings as independent elements on the page, for example, to create clickable tags or present them as a list, then the `split` filter and `for` loop combination provided by the AnQiCMS template is the powerful tool to achieve this goal.

2025-11-08

If the delimiter parameter of the `split` filter is empty, how will it split a Chinese string?

In Anqi CMS template development, the `split` filter is a very practical tool that can help us flexibly handle string data, splitting it into an array according to the specified delimiter.This is very useful in many content display and data processing scenarios.But sometimes, under certain specific requirements, we may encounter a seemingly "blank" delimiter parameter, which raises an interesting question: What if the delimiter parameter of the `split` filter is empty, how will it cut Chinese character strings?

2025-11-08

Will the array obtained by passing the `split` filter be identical when concatenated back into a string using the `join` filter?

In Anqi CMS template development, we often encounter scenarios where we need to process strings.The `split` and `join` filters are very commonly used tools for handling such needs.`split` can split a string into an array using a specified delimiter, while `join` can concatenate the elements of an array using a specified delimiter to form a new string.Then, when we use the `split` filter to split a string into an array and then use the `join` filter to concatenate the array back into a string

2025-11-08

Can the `split` filter handle multi-character delimiters, such as splitting a string with "`||`" as the delimiter?

In website content operation, we often encounter situations where we need to process strings.For example, extract multiple tags, keywords from a text field, or split stored data according to specific rules and display them separately.The template engine of AnQiCMS (AnQiCMS) provides rich filters to help us achieve these operations, among which the `split` filter is a powerful tool for string splitting.

2025-11-08

The length of the array split by the `split` filter can be obtained through which filter?

During the template development process of AnQi CMS, we often need to handle various data, among which string processing is particularly common.For example, you may need to split a string containing multiple keywords, such as "SEO, website optimization, content marketing", by commas and spaces to display one by one on the page or perform other logical judgments.After a string is successfully split into several parts, we may need to know the number of these parts, which is the length of the array.Luckyly, Anqi CMS provides a concise and efficient filter combination to solve this problem: `split`

2025-11-08

How to determine if a specific element is included in the array split by the `split` filter?

During content management and template development, we often encounter the need to process a string and then determine whether the processed result contains specific information.For example, a document may have multiple tags or categories, and this information is usually stored as a string connected by separators such as commas.When we need to decide the display style of the page based on these tags or categories, it is particularly important to judge whether it contains a specific element.AnQiCMS provides powerful template tags and filters, making such operations simple and intuitive.

2025-11-08