How to customize fields in the AnQiCMS backend where a field stores multiple choices (an array), and clearly display them on the frontend page using the `join` filter?

Calendar 👁️ 58

AnQi CMS provides great convenience for website operators with its flexible content model and powerful custom features.In daily content management, we often encounter situations where we need to add multiple choice attributes to articles or products, such as a product may have various colors, different sizes, etc.When this information is stored in the background through custom fields in the form of multiple-choice values, how to display them in a clear and beautiful way on the front-end page has become the problem we need to solve.

Understand the multiple custom fields of AnQi CMS

In the Anqi CMS backend, we can manage content models to create custom fields for different content types (such as articles, products).Among the 'multiple choice' type fields, the content editor is allowed to select multiple preset values for a content item.For example, define a “Color” field for a product and set optional values “Red”, “Blue”, “Green”, and you can check “Red” and “Blue” at the same time when editing.

After these multi-select values are stored, the system usually saves them in the form of an array (or a string connected by a specific delimiter, but the front-end template engine recognizes it as an iterable list). If you output this field directly in the front-end template, you will often see the raw data without any processing, such as["红色", "蓝色"]or红色,蓝色This is obviously not aesthetically pleasing and user-friendly.

Accessing custom field data in the front-end template.

To display these custom fields on the front-end page, we first need to obtain them through the template tags provided by Anqi CMS. The most common way is to usearchiveParamsLabel to iterate over all custom parameters, or access them directly by field name.

For example, on the document detail page, we can retrieve all custom fields in this way:

{% archiveParams params %}
    {% for item in params %}
        <div>
            <span>{{item.Name}}:</span>
            <span>{{item.Value}}</span>
        </div>
    {% endfor %}
{% endarchiveParams %}

If your multiple choice field is namedproductFeaturesyou can also try to access it directly:

{% archiveDetail productFeatures with name="productFeatures" %}
{{ productFeatures }}

However, whether through looping or direct access, for the multiple choice fieldproductFeaturesofitem.ValueorproductFeaturesthe output result may still be similar["特点A", "特点B", "特点C"]This is the original array string. This is exactly where we need to optimize.

Skillfully usejoinFilter, to clearly display multiple choices.

To convert this array-formatted original data into an easily readable string, the Anqi CMS template engine provides a very practical filter:join.joinThe filter's function is to concatenate all elements of an array (or any iterable object) into a single string with the specified separator.

joinThe basic usage of the filter is{{ obj|join:"连接符" }}. Among them,objis the array or list you want to process, and"连接符"is the string you want to insert between elements, such as commas, colons, slashes, or any custom text.

Now, let's see how to convertjoinApply the filter to the display of the multi-select custom field.

Scenario one: ByarchiveParamsTraversal to display all custom fields

Assuming you have a multi-select field named "Product Features", you have entered multiple values such as "Waterproof", "Shockproof", "Smart Connectivity", etc. in the backend. In the frontend template, you can handle it like this:

{% archiveParams params %}
    {% for item in params %}
        {% if item.FieldName == "productFeatures" %} {# 假设 productFeatures 是您的多选字段的调用字段名 #}
            <div>
                <span>{{item.Name}}:</span>
                {# 将多选值用中文顿号连接,使其更符合阅读习惯 #}
                <span>{{ item.Value|join:"、" }}</span>
            </div>
        {% else %}
            {# 其他非多选字段的正常显示逻辑 #}
            <div>
                <span>{{item.Name}}:</span>
                <span>{{item.Value}}</span>
            </div>
        {% endif %}
    {% endfor %}
{% endarchiveParams %}

In the above code, we first determine the current loopeditemwhether it is our multiple choice field. If it is, we proceed toitem.Valueapplyjoin:"、"The filter connects its elements with a comma. This way, on the front-end page, you will see 'Product features: Waterproof, Shockproof, Smart Connection' instead of the original array format.

Scenario two: Directly access and display a known name of a multi-select custom field

If you know the name of a specific multi-select field (for example, its calling field isproductFeatures),You can obtain and display it more directly:“

{% archiveDetail productFeatures with name="productFeatures" %}
    {% if productFeatures %} {# 检查字段是否有值,避免显示空行 #}
        <div>
            <span>产品特点:</span>
            {# 使用斜杠和空格作为连接符,适用于产品参数等场景 #}
            <span>{{ productFeatures|join:" / " }}</span>
        </div>
    {% endif %}

This code first goes througharchiveDetailtag to obtainproductFeaturesApply it directly to the value of the field,“join:" / "Filter. So, if the field is selected with 'FeatureA' and 'FeatureB', the page will display 'Product Features: FeatureA / FeatureB'.

ByjoinThe filter allows us to transform complex data structures in the backend into clear and readable display content on the front end.You can choose different connectors (such as commas, colons, slashes, or any text) according to your actual needs to make your website content more professional and beautiful.


Frequently Asked Questions (FAQ)

1.joinWhat types of data can the filter handle? Is it effective for all fields? joinThe filter is mainly used to process array (slice) or data types that the system can recognize as a list (for example, a comma-separated string). In AnQi CMS, the values of multiple-choice custom fields are usually recognized by the template engine as iterable lists, thereforejoinFilters can be applied to them well. For single-line text, numbers, and other non-list fields,joinFilters may treat them as a list with a single element (for example,{{ "hello"|join:"-" }}Possible outputh-e-l-l-oTherefore, it is recommended to use it only when it is indeed a multi-choice or list field.

2. If my multi-choice field has no selected value in the background, the frontend applicationjoinWhat will be displayed after the filter?When a multi-select field has no values selected, its value is typically an empty array or an empty list. Applying a function to an empty listjoinA filter, by default, will return an empty string. If you do not want to display whitespace, you can use conditional judgment in the template ({% if productFeatures %}) to control, or combinedefaultSet a default display text for the filter, for example{{ productFeatures|join:"、"|default:"暂无" }}.

3.joinFilters andsplitWhat are the differences between filters? When would you use themsplit? joinThe filter 'joins' array elements into a single string,splitThe filter works in the opposite way, it splits a string into an array using a specified delimiter. If you store a plain text string in the backend custom field (instead of a multi-select field automatically generated list), and this string is represented by a specific delimiter (such as a comma) to indicate multiple values, then you may need to usesplitThe filter splits the string into an array and then uses itjoinThe filter displays it in another way, for example:{{ "值1,值2,值3"|split:","|join:" / " }}It will output.值1 / 值2 / 值3.

Related articles

What will happen when the `join` filter encounters an array with mixed data types (such as strings and numbers)?

In Anqi CMS template development, the `join` filter is a very useful tool that can help us concatenate multiple elements of a list (array) into a complete string.This is particularly convenient when it is necessary to display a series of related data in a unified format, such as displaying multiple tags of articles, multiple characteristics of products, or multiple permissions of users.However, in practice, we sometimes encounter situations where the array to be concatenated contains different types of data, such as strings, numbers, and even boolean values. So

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

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

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 language, what are the similarities and differences between the `join` filter and other string concatenation methods, and what are their applicable scenarios?

In Anqi CMS template language, combining multiple strings or data fragments into a complete string is a very common requirement in front-end display.There are many ways to achieve this goal, each method has its unique application scenarios and advantages.Today, let's delve into the differences and similarities between the `join` filter and other commonly used string concatenation methods.### `join` filter: A bridge from array to string The `join` filter plays a very clear and efficient role in AnQiCMS template language

2025-11-08

How to split a string containing multiple keywords in AnQiCMS template by spaces, commas, or a custom delimiter into an array?

In AnQiCMS (AnQiCMS) content management and template development, we often encounter scenarios where we need to process strings containing multiple keywords.For example, an article may have a comma-separated list of keywords, or product attributes are space-separated tags.Make full use of these data and display them flexibly in the template, you need to split these strings into traversable arrays precisely.AnQiCMS uses a template engine syntax similar to Django, providing powerful filter functions to handle such needs.Among, `split`

2025-11-08

The `make_list` filter and the `split` filter are applicable to which scenarios in converting strings to character arrays in AnQiCMS templates?

In AnQiCMS template development, we often need to process string type data, where converting a string to an array is a common requirement.AnQiCMS powerful template engine provides a variety of filters to assist in completing such tasks, among which the `make_list` and `split` filters are the tools for converting strings to arrays.Although they can both 'turn' strings into arrays, there are essential differences in their application scenarios and conversion logic.Understanding these differences can help us achieve template functionality more efficiently and accurately.##

2025-11-08

How to get the actual length of a string or array in AnQiCMS template (number of characters or elements)?

When managing website content in AnQi CMS, you often encounter situations where you need to get the number of characters in text or determine how many elements are in a list or array.In order to control the page layout, ensure the display length of the title introduction, or dynamically adjust the display logic based on the amount of data, it is crucial to understand how to obtain this "length" information in templates for creating flexible and user-friendly websites.The AnQi CMS template engine provides a concise and powerful way to handle such requirements, with the most core being the `length` filter

2025-11-08