How to concatenate the tag array in AnQiCMS template into a string with a custom delimiter?

Calendar 👁️ 76

In AnQiCMS template development, we often need to display a set of data obtained from the database, such as the multiple tags (Tags) of an article, in a user-friendly manner, rather than simply listing them.One of the most common needs is to concatenate these tags into a string with a custom delimiter, such as AnQiCMS offers a powerful template engine that provides a flexible way to achieve this goal.

Understand the data structure of AnQiCMS templates

AnQiCMS's template uses syntax similar to Django, with its core advantage being the ability to easily retrieve data from the backend and render it on the frontend. When we use liketagListSuch a label to get the tags of the document, it usually returns an array or slice containing multiple 'tag objects'. Each 'tag object' itself may containTitle(label name),Link(Tag link) and multiple fields.

For example, by{% tagList tags %}Tags like this, we get.tagsThe variable is not a simple string array, but an array of multiple likes.TagThis structure is composed of an array. If we try to perform certain operations on it directly, we may not get the results we want.

To clearly demonstrate this, we usually use templates infora loop to iterate over these tags, like this:

{# 假设我们正在一个文档详情页,获取当前文档的标签 #}
{% tagList tags with itemId=archive.Id limit="10" %}
    {% for item in tags %}
        <a href="{{item.Link}}">{{item.Title}}</a>
    {% endfor %}
{% endtagList %}

This code will output the links and titles of each tag separately, but they are scattered HTML elements. Our goal is to concatenate{{item.Title}}these strings.

UsejoinFilter implementation

Related articles

In AnQiCMS template, how to convert a string number into an actual `integer` or `float` type?

When working with the Anqi CMS template to display content and make logical judgments, we often encounter situations where we need to perform operations on numbers.However, data obtained from a database or content model, even if it looks like a number in the background, is sometimes passed as a string (``string``) at the template level.If this is directly performed arithmetic operations or numerical comparisons, unexpected results may occur.

2025-11-08

How to find the first occurrence index of a character or substring in the AnQiCMS template?

During the process of displaying website content or template development, we often encounter situations where we need to process specific text, such as checking if a keyword exists or locating the first occurrence of a character or substring.The template engine of AnQiCMS (AnQiCMS) provides a series of powerful filters (Filters) to help us complete these tasks efficiently.Today, let's discuss how to use the `index` filter to accurately find the position index of the first occurrence of a character or substring in the AnQiCMS template.Understand

2025-11-08

How to extract specific number information from a long numeric string in AnQiCMS template?

In website operations, we often encounter scenarios where we need to handle some structured long numeric string.For example, a product code may contain the production date and batch information; an order number may imply regional codes and serial numbers; or may be a unique identifier generated by specific business logic.These long digital strings often carry rich metadata, and we may only need the numerical information at specific positions for display, filtering, or further processing.

2025-11-08

How to precisely control the display of floating-point numbers in the AnQiCMS template, such as retaining two decimal places?

In website content operation, the way numbers are presented often affects user experience and the accuracy of information.Especially for floating-point numbers, such as product prices, statistics, and ratings, it is common to require accuracy to several decimal places or rounding according to business needs.AnQiCMS is a powerful template system that provides us with a flexible way to handle these data.Today, let's delve into how to efficiently and accurately control the display of floating-point numbers in the AnQiCMS template.

2025-11-08

How to get the total length of elements in a string, array, or key-value pair in AnQiCMS template?

In AnQi CMS template design, dynamically obtaining the total length of elements in a string, array, or key-value pair is a very practical feature. It can help us flexibly display information on the page, such as showing the number of products, the number of comments, or adjusting the layout according to the content length.The Anqi CMS template engine provides simple and efficient filters to meet these requirements.### Core Tool: `length` Filter The most direct and universal method to obtain the total number of elements in any string, array (slice), or key-value pair (map/struct) is to use

2025-11-08

How does the AnQiCMS template automatically convert line breaks in text to HTML tags such as `<p>` or `<br>`?

In website content presentation, text formatting is often the key to determining the user's reading experience.We often encounter such needs: the text content obtained from the background database usually only contains simple newline characters (`\n`), and if it is displayed directly on the web page, the browser will not intelligently convert these newline characters into the HTML paragraph (`<p>`) or line break (`<br>`) tags we expect, causing the content to be cramped together and lose its original structure and readability.AnQiCMS (AnQiCMS) has fully considered this point in template design

2025-11-08

How to dynamically define and use small array variables for loops in AnQiCMS templates?

In AnQiCMS template development, we often need to flexibly display some small data sets according to business logic.These collections may be some custom tags, navigation items, or just some status identifiers.Although AnQiCMS provides rich tags to call background data, sometimes we want to define a small array directly in the template and loop through it to achieve finer control and simpler template code.

2025-11-08

How to convert letter combinations like 'PONGO2' into the corresponding numbers on a phone keypad?

How to easily convert letter combinations to phone number keypad digits in AnQiCMS?In daily life, we sometimes encounter some phone numbers composed of letters and numbers, for example, some companies may use memorable numbers like "999-PONGO2" for brand promotion.However, when making a phone call in reality, these letters need to be converted into the corresponding numbers on the phone keypad.For website operators, if they can automatically complete this conversion on the website front end, it will undoubtedly greatly improve the user experience.

2025-11-08