When using the `join` filter, besides commas, what characters does AnQiCMS support as delimiters for joining array elements?

Calendar 👁️ 58

When developing with AnQiCMS templates, we often need to combine multiple elements in an array into a string for display, whether it is used to build navigation, display keywords, or format data lists. At this point,joinThe filter has become our powerful assistant. Many users may only be familiar with using commas (,) as connectors, but actually, it is AnQiCMS'sjoinThe filter offers a wider range of choices, its capabilities far exceed this.

joinThe principle of the filter.

joinThe filter is used to concatenate all elements of an array (or slice) using a specified delimiter to form a single string. Its syntax is very intuitive:

{{ 你的数组变量 | join:"你想要的分隔符" }}

For example, if you have a variable namedkeywordsarray containing["AnQiCMS", "内容管理", "高效"]and hope to connect them with a comma and space, you can write it like this:

{{ keywords|join:", " }}

The output will be:AnQiCMS, 内容管理, 高效.

Break the limit of commas: more options of connecting symbols

AnQiCMS'joinThe filter is designed to be very flexible, it is not limited to using commas. In fact, you can useany string you wantTo be used as an array element separator. This means you can choose the most suitable character, symbol, or even HTML tag to connect your array elements in order to achieve **display effects or data formats.

For example, if you want to use a hyphen-Connect a group of keywords to generate a SEO-friendly URL segment:

{% set productTags = ["智能手机", "安卓系统", "旗舰机型"] %}
<a href="/products/tag/{{ productTags|join:"-" }}">查看更多</a>

This might generate something similarproducts/tag/智能手机-安卓系统-旗舰机型URL.

For example, you may need to use some product features to|Concatenate the symbols so that they are clearly displayed on one line:

{% set features = ["高分辨率屏幕", "超长续航", "AI芯片"] %}
<span>特点:{{ features|join:" | " }}</span>

It will be output:特点:高分辨率屏幕 | 超长续航 | AI芯片.

This flexibility allowsjoinThe filter is very useful in many scenarios. You can use it to:

  • Build semantically meaningful URL or filename- Use hyphens-or underscores_.
  • Format data list- Use tabs\tcarriage return\n/<br>(Remember to配合|safeFilter, or use a custom delimiter such as---.
  • Create a navigation menu or breadcrumb path: Use.>or/.
  • Generate a unique identifier or combination of strings: Customize the connector based on business logic.

A connector can be a single character or a string made up of multiple characters. For example, you can even use HTML tags as a connector, but remember that when the connector contains HTML, you need to use|safeA filter to ensure they are not escaped but are correctly parsed by the browser:

{% set listItems = ["首页", "产品", "关于我们"] %}
<ul><li>{{ listItems|join:"</li><li>"|safe }}</li></ul>

The above code generates an unordered list, with each array element being<li>tag wrapping.

Use tips

  1. The input must be an array or a slice:joinThe filter is primarily designed to process arrays or slices. If you apply it to a string, it will treat each character of the string as an element and then connect them with the specified separator. For example,{{ "你好世界"|join:"-" }}It will output.你-好-世-界.
  2. Note HTML escaping: If your connector or array element contains HTML tags and you want these tags to be parsed by the browser rather than displayed as plain text, be sure tojoinafter the filter|safeFilter, for example{{ array|join:"<br>"|safe }}.
  3. Select the appropriate connector based on the scenario: There is no best connector, only the one that best suits your current display needs.For example, for URLs, hyphens are usually preferred over commas by search engines;For the display on the user interface, spaces, vertical lines, or custom delimiters may be clearer.

By flexible applicationjoinFilter, you can easily convert the array data of AnQiCMS templates into various string formats to better meet the needs of website content display and functional implementation.


Frequently Asked Questions (FAQ)

Q1:joinCan the filter connect array elements of non-string type?A1: Yes, AnQiCMS'sjoinThe filter is very intelligent. It automatically converts non-string elements in the array (such as numbers, booleans, etc.) to strings before connecting them with the specified delimiter.So, you do not need to manually convert data types.

Q2: If the array to be connected is empty,joinwhat will the filter return?A2: If you use an empty arrayjoinA filter that returns an empty string. This is convenient to use because you usually don't need extra condition checks to handle empty array cases.

Q3:joinFilters andsplitWhat does the filter have to do with it?A3:joinandsplitThe filter is a complementary operation.splitThe filter is used to split a string into an array according to a specified delimiter (for example, to split"AnQiCMS,内容管理"Split into["AnQiCMS", "内容管理"])。WhilejoinThe filter works in the opposite way, it concatenates array elements into a string using a specified separator. Both are often used together when converting between strings and arrays.

Related articles

How to connect multiple tags (Tag) in AnQiCMS template into a comma-separated keyword string?

In website operation, article tags (Tag) not only help in categorizing and retrieving content, but also enhance the page's SEO effect through keywords.Many times, we need to display multiple tags separated by commas at specific locations on the page, such as within the `<meta name="keywords">` tag or at the bottom of the article content."}AnQiCMS (AnQiCMS) provides a concise and flexible template syntax, making this operation very direct.### Understand the source of article tag data In AnQi CMS

2025-11-08

How to ensure that a number converted to `float` or `integer` is correctly identified as `true`/`false` in an `if` condition?

When using AnQiCMS for website content management, we often encounter scenarios where we need to make judgments and process data.Especially when data comes from user input or external interfaces and the type is uncertain, how to correctly identify the number converted through `float` or `integer` filters in the `if` condition judgment in the template is the key to ensuring logical accuracy. The AnQiCMS built-in template engine is powerful, supporting `float` and `integer` type conversions in GoLang.Understand the behavior of these transformation filters in different situations

2025-11-08

What happens when one of the operands is `nil` or empty while using the `add` filter?

In AnQiCMS template development, the `add` filter is a very practical tool that allows us to perform addition operations on numbers or strings, providing convenience for template logic processing.However, when an empty value (empty value) or `nil` appears in the operands of addition, the result may puzzle some users who are new to the subject.Today, let's delve into the behavior of the `add` filter in this specific case.Firstly, the `add` filter is designed to be very flexible, it can not only handle the addition of pure numbers, but also intelligently concatenate strings

2025-11-08

How to convert a numeric field in a template to a string without affecting other logic?

In AnQiCMS template development, we often encounter scenarios where it is necessary to display numeric data combined with text content.For example, you may need to add the product ID at the end of a product title, or add “times read” after the number of reads in an article.How to flexibly convert numeric fields in templates to strings and concatenate them without affecting other logical judgments or calculations?It's lucky that

2025-11-08

How does the `join` filter handle an empty array or an array with only one element in the AnQiCMS template?

In Anqi CMS template development, the `join` filter is a very practical tool that can concatenate multiple elements of an array (or list) with a specified delimiter to form a continuous string.This is very convenient when it comes to dynamically generating paths, tag lists, or any comma-separated values.In most cases, when we have an array containing multiple elements and use the `join` filter, its behavior is as expected.For example, if we have an array named `fruit_list` that contains `["apple",}

2025-11-08

How to extract and concatenate a specific field (such as Category ID) from a document list obtained through the `archiveList` tag?

When using AnQiCMS for website content management, we often need to extract specific information from the document list and combine it in some format, such as connecting a series of document category IDs into a string for front-end dynamic rendering, SEO optimization, or specific data statistics.Although AnQiCMS's template system provides powerful data acquisition capabilities, it requires us to skillfully use its built-in tags and filters to directly implement this 'extract-combine' logic in the template.### Core Challenge

2025-11-08

In AnQiCMS template, how to reassemble a string array split by `split` filter using the `join` filter into a custom formatted string?

In AnQiCMS template development, handling string data is one of the daily tasks.Sometimes, the strings we retrieve from the database may contain multiple values separated by a specific character, such as multiple keywords in an article, which may be stored in the form of In order to flexibly display this data on the front-end page, for example, to turn each keyword into a clickable tag or display it with different delimiters, we need to use the powerful string processing filters - `split` and `join` in the AnQiCMS template.

2025-11-08

Can the `join` filter in AnQiCMS template handle array elements containing Chinese characters correctly? If so, what are the precautions?

In AnQiCMS template development, the `join` filter is a very practical tool that can concatenate all elements of an array (or slice) with a specified separator to form a single string.For many users concerned, can the `join` filter correctly handle array elements containing Chinese characters? The answer is affirmative.AnQiCMS is developed based on Go language, Go language supports UTF-8 encoding natively, which means it has a natural advantage in handling multi-language characters. Therefore

2025-11-08