Array concatenation into a string: Application scenarios of the `join` filter in AnQiCMS templates?

Calendar 👁️ 59

In website content management, we often encounter the need to display a set of data, such as multiple tags, multiple image URLs, or custom multi-select content, as a unified string format.AnQiCMS (AnQiCMS) relies on its efficient architecture based on the Go language and the flexible template engine similar to Django, providing great convenience for content display.Today, let's take a deep look at a very useful tool for handling such needs -joinfilter.

joinWhat is a filter?

in the AnQi CMS template world,joinThe filter plays the role of concatenating all elements from an array (or an iterable object) with a specified delimiter, ultimately forming a single string.Its syntax is concise and intuitive, one can understand its intent at a glance.

The basic usage is very direct, you just need to pass the array variable to be processed through the pipe symbol|pass tojoinFilter, and specify the separator you want to use after it, enclosed in double quotes.

For example, assume you have an array containing multiple category names in the template:

{% set categories = ["科技", "生活", "旅游"] %}
<div>当前分类:{{ categories|join(" - ") }}</div>

After rendering, the display on the page will be:当前分类:科技 - 生活 - 旅游

By changing the separator, you can easily adjust the style of the output, such as using commas, slashes, or any other characters you need.

joinThe core application scenario of the filter

joinThe filter can shine in various content display scenarios, helping us present data in a more beautiful and practical way.

1. Integrate multi-value tags or keywords

In AnQi CMS, the Tag feature of articles or products is very powerful, you can add multiple related tags for content in the background. AlthoughtagListTags are usually used to display each tag and its link in a loop, but under certain design requirements, you may want to simply concatenate all tag names into a string, such as displaying a related keyword cloud at the bottom of the page, or listing all tags in the article summary.

Assuming you have a custom field that stores multiple keywords for the article and retrieves them in an array format:

{# 假设 archive.CustomKeywords 是一个字符串数组 #}
{% archiveDetail archiveKeywords with name="CustomKeywords" %}
<p>文章关键词:{{ archiveKeywords|join("、") }}</p>

This code will connect all custom keywords in the article with Chinese commas “、” to form a smooth keyword list.

2. Enhance content display: image path or file list

Anqi CMS allows setting group images for content (such asImagesfield), this usually returns an array of image URLs. In some simple scenarios where a carousel is not suitable, or when you need to use these image paths in JavaScript logic,joinThe filter can be useful.

For example, you might want to display all the cover image paths of an article on a single line, for debugging or some non-visual display scenarios:

{% archiveDetail galleryImages with name="Images" %}
<p>所有图片URL:{{ galleryImages|join("; ") }}</p>

The page may output:所有图片URL:/uploads/img1.webp; /uploads/img2.webp; /uploads/img3.webp

3. Combine the values of custom multi-select fields

The AnQi CMS flexible content model allows you to define various custom fields, among which the 'Multiple Selection' type of field often returns a string array when retrieved on the frontend. If you need to present the multiple options selected by the user in a concise manner,joinThe filter is an ideal choice.

For example, a product model may have a multi-select field named "Features", whose values may include["高性能", "易用性", "高安全性"]:

{% archiveDetail productFeatures with name="features" %}
<p>产品主要特点:{{ productFeatures|join(" | ") }}</p>

This will connect all the product features with the vertical bar symbol “|” and clearly display them to visitors.

4. AndsplitCombined with the filter, it achieves flexible string conversion.

jointhe filter meetssplitThe filter (used to split a string into an array by delimiter) combines to unleash its full power, enabling various complex text format conversions.You can use this method to convert a string stored in a specific format on the back-end into another display format on the front-end.

Assuming a certain field in the background stores a comma-separated list of keywords:

{% set rawKeywords = "Go语言,AnQiCMS,模板引擎,SEO优化" %}
<p>相关主题:{{ rawKeywords|split(",")|join(" - ") }}</p>

Here, we first usesplit(",")Split the string into an array using commas and use it immediatelyjoin(" - ")Translate this array with "-". The final output will be:相关主题:Go语言 - AnQiCMS - 模板引擎 - SEO优化

This combination provides great flexibility for front-end display, and you can meet the design requirements without changing the background data storage format

Related articles

What is the difference between the `make_list` filter and the `split` filter? When should `make_list` be used to split strings?

In AnQi CMS template development, we often need to process string data, such as splitting a long string into multiple independent parts for traversal, display, or further logical judgment.Anqi CMS provides a variety of filters (Filters) to help us complete these tasks, among which `make_list` and `split` are two commonly used string splitting tools.Although they can all convert strings to lists (or arrays), there are obvious differences in their functional focus and usage scenarios.

2025-11-08

`split` filter: How to split a long string into an array by a specific delimiter?

In the powerful functions of AnQi CMS, the flexibility of content display has always been our focus.Sometimes, you may need to enter a long string of information in a field on the back end, such as multiple keywords for an article, multiple parameters for a product specification, or a list of skills for a team member.This information is usually connected by specific delimiters (such as commas, semicolons, or pipes).However, when you want to display this information individually on the front page, even to style each part differently, the problem arises: how can you conveniently split this long string into independent items?

2025-11-08

What are the limitations of the `first` and `last` filters when getting the first and last elements of a string/array?

In Anqi CMS template design, the `first` and `last` filters are two concise and practical tools designed to help us quickly obtain the first or last character of a string, as well as the first or last element of an array.They perform well in handling simple data structures, but in practical applications, if their internal mechanisms are not well understood, they may encounter some unexpected behaviors.Firstly, let us understand their core functions. For string type data, `first` will return the first character, and `last` will return the last character

2025-11-08

How can you quickly get the first element of an array or the first character of a string in a template?

In Anqi CMS template development, efficiently obtaining data is the key to improving website performance and user experience.Whether it is dealing with a document list or image group obtained from the background, or operating on a common string, we often encounter the need to extract the first element of an array or the first character of a string.The Anqi CMS, based on Go language and Django template engine syntax, provides various intuitive and practical methods to achieve this goal.

2025-11-08

How to safely truncate the article content using the `truncatechars_html` filter without destroying the HTML structure for website SEO?

In website operation, we often need to display the concise content of articles in article lists, search results summaries, or social media shares.This concise content should not only attract users' attention, but also ensure that the complex HTML structure behind it is not damaged, in order to avoid affecting the layout and user experience.For search engine optimization (SEO), a clean and effective code structure is crucial. AnQiCMS (AnQiCMS) is an enterprise-level content management system developed based on the Go programming language, deeply understanding the pain points and needs of website operation.It not only provides multi-site management, a flexible content model

2025-11-08

Template content shows: How does the `truncatewords` filter truncate text by word count?

In the presentation of website content, we often need to condense lengthy text information to meet different layout requirements, such as displaying article summaries on list pages, brief descriptions on product cards, etc.This not only makes the page look neater, but also helps visitors quickly grasp the core information.AnQiCMS provides flexible template filters for this type of need, where the `truncatewords` filter is your powerful assistant for truncating text by word count.### A clever and concise summary, making the content clear at a glance

2025-11-08

How to get a specific digit from a number: Advanced usage of the `get_digit` filter in AnQiCMS template?

In AnQiCMS template development, flexible handling and displaying data is the key to enhancing website functionality and user experience.When faced with a sequence of numbers, such as product numbers, order numbers, or some kind of identification code, sometimes we do not need the entire number, but rather a specific digit at a certain position.At this time, the `get_digit` filter has become a very practical tool.It can help us extract the required part from the numbers accurately, providing more possibilities for the dynamic display of templates and logical judgment.

2025-11-08

What is the role of the `index` filter in processing string searches?

In the AnQiCMS template world, efficiently processing and displaying content is the core.Whether it is to dynamically adjust the page display based on user input or quickly locate key information in complex text, mastering the template function can greatly improve the operation efficiency of your website content.Today, let's delve into a very practical tool for string searching—the `index` filter.### `index` filter: 'Locate Expert' string Imagine you have a long article content or a list with multiple tags

2025-11-08