How to filter the items to display in the `archiveParams` loop based on the custom parameter name?

Calendar 👁️ 65

As an experienced website operations expert, I know that the flexibility of a content management system (CMS) is the key to whether the website can respond quickly to market changes and optimize the structure of content.AnQiCMS (AnQiCMS) offers us great convenience with its powerful custom content model function.However, it is not enough to simply define custom parameters, how to flexibly call and filter these parameters according to actual needs is a practical problem faced by many operators and developers.Today, let's delve deep into how toarchiveParamsIn the loop, accurately filter out the content we want to display based on the name of the custom parameters.

Understand the custom parameter mechanism of AnQiCMS.

Before delving into the filtering strategy, we first need to clarify how the custom parameters operate in the Anqí CMS.One of the core advantages of AnQi CMS is its highly flexible content model.Whether it is articles, products, or any other type of content, we can add various dedicated fields according to business needs, which are what we often call 'custom parameters'.

The definition of these custom parameters is usually carried out in the "Content Management" module on the backend, the specific path is "Content Management" -> "Content Model" -> Select or create a model -> "Custom Field".Here, you will set a 'parameter name' for each custom parameter (this is used in the backend interface and frontend template to identify and display it) and a 'calling field' (this is the unique identifier used internally for storage and access through programming interfaces).

When we fill in these custom fields on the editing page of the document (or product and other content), this data will be stored with the document. In the front-end template, we can then usearchiveParamsLabel to get this additional information.

archiveParamsThe core role of tags

archiveParamsThe tag is a powerful tool in Anqi CMS template used to obtain all custom parameters of the current document or a specified document. Usually, we use it like this:

{% archiveParams params %}
    {% for item in params %}
        {# 这里的 item 包含了自定义参数的 Name(参数名)和 Value(参数值) #}
        <p>{{ item.Name }}:{{ item.Value }}</p>
    {% endfor %}
{% endarchiveParams %}

In this code block,archiveParamsThe tag assigns all custom document parameters as an array toparamsthe variable. Then, we useforLoop through thisparamsEach element of theitemrepresents a custom parameter. By default,archiveParamswill be usedsorted=trueThe way to return an ordered array, eachitemcontains two key properties:Name(which is the parameter name you set in the background) andValue(which is the specific content of the parameter).

However, merely traversing and displaying all parameters is not enough in many cases.For example, you may define multiple parameters such as "author", "publisher", "ISBN", "page number", etc. for an article, but in a certain area of the page, you only want to highlight the information of "author" and "publisher", while other parameters are placed in another more detailed area of the page.At this point, we need to filter in the loop.

In the loop, filter parameters based on name

Resolve inarchiveParamsThe method of filtering specific parameters in the loop is combined with the AnQiCMS template engineforloop andifConditional judgment tags. BecausearchiveParamsEach in the loopitemAll providedNameProperties, we can directly use this property to compare and thus filter out the parameters we want to display.

Imagine a scenario: you have a "book" content model, to which you have added custom parameters such as "author", "publisher", "publish date", "ISBN", and so on.Now, you want to display only 'author' and 'publisher' information in the article summary card.You can implement it like this:

<div class="book-info-card">
    <h3>书籍信息概览</h3>
    {% archiveParams bookDetails with sorted=true %}
        {% for detail in bookDetails %}
            {# 根据参数名(item.Name)进行条件判断 #}
            {% if detail.Name == "作者" or detail.Name == "出版社" %}
                <p><strong>{{ detail.Name }}:</strong> {{ detail.Value }}</p>
            {% endif %}
        {% endfor %}
    {% endarchiveParams %}
</div>

In this code block:

  1. We use{% archiveParams bookDetails with sorted=true %}Get all the custom parameters of the current document and store them inbookDetailsthe variable.
  2. {% for detail in bookDetails %}Loop through each custom parameter.
  3. The core lies in{% if detail.Name == "作者" or detail.Name == "出版社" %}This line. It will check the current parameter'sNameIs the attribute equal to "author" or "publisher"?
  4. Only when the condition is met,ifThe content inside the tag (<strong>{{ detail.Name }}:</strong> {{ detail.Value }}) will be rendered.

In this way, evenarchiveParamsObtained all the custom parameters of the document, we can also flexibly display the information we need on the front-end page according to the parameter name, which greatly enhances the refinement and maintainability of content display.

Related articles

How to safely render `archiveParams` tag if the document parameters contain HTML content?

AnQiCMS (AnQiCMS) is a powerful content management system developed based on the Go language, with flexible content models and customizable document parameter functions, providing great freedom for enterprises and content operators.This means we can create unique fields for articles, products, and other content to meet personalized display needs.

2025-11-06

How to judge whether a custom parameter exists and display in AnQiCMS via the `archiveParams` tag?

In the powerful content management system of AnQi CMS, custom parameters (also known as content model custom fields) are an important manifestation of its flexibility.It allows operators to add personalized data to content models such as articles, products, etc. according to specific business needs.But in the front-end template, we often need to determine whether a custom parameter exists or has been assigned a valid value before deciding whether to display it.This is when the `archiveParams` tag becomes an indispensable tool.##

2025-11-06

The `archiveParams` tag returns custom parameters, is the data structure a fixed array or a variable Map?

Hello, all website operators and AnQi CMS enthusiasts! Today, we will delve into a practical and flexible tag in the Anqi CMS template development——`archiveParams`.Many times, when using custom parameters, there is a question: What is the data structure of the custom parameters returned by the `archiveParams` tag, whether it is a fixed array or a variable Map?In order to better utilize the strong content model customization capabilities of Anqi CMS, it is crucial to understand this point.This article will explain in detail

2025-11-06

How to implement cross-site calls for the `siteId` parameter of the `archiveParams` tag in the AnQiCMS multi-site environment?

## Mastering AnQi CMS Multi-Site: Cross-Site Call Practice of `archiveParams` Tag SiteId Parameter As an experienced website operations expert, I fully understand that efficient content management and flexible content scheduling are the keys to business success in increasingly complex network environments.AnQiCMS (AnQiCMS) provides powerful tools for operators with its excellent multi-site management capabilities.Today, let's delve into a very practical feature in a multi-site environment

2025-11-06

What is the main purpose of the Tag label function in Anqi CMS?

As an experienced website operations expert, I know that in the increasingly fierce online competition, content must not only be of high quality but also easy to find and organize.AnQiCMS (AnQiCMS) provides us with a comprehensive and efficient content management solution with its powerful functions.Today, let's delve deeply into one of the seemingly simple yet potentially powerful features - Tag label, and see what role it plays in our content operation strategy.

2025-11-06

How to add Tag tags for articles or products in the Anqi CMS backend?

As an experienced website operations expert, I know that the core value of a content management system (CMS) lies in its ability to efficiently and flexibly support content operation strategies.AnQiCMS (AnQiCMS) offers an excellent solution in content publishing and management with its powerful feature set.Today, let's delve deeply into a seemingly simple but crucial feature for content organization and search engine optimization (SEO): how to add Tag tags for articles or products in the AnQiCMS backend.

2025-11-06

What is the core difference between Tag tags and content categories?

As an experienced website operations expert, I know that how to effectively organize content in a powerful content management system like AnQiCMS is the key to the success of the website.Content categories and Tag tags are both important tools we use to manage and present information, but they have essential differences in design philosophy, functional focus, and application scenarios.Understanding these core differences will help you better plan the website structure, improve user experience, and optimize search engine performance.

2025-11-06

How many Tag labels can I add to a document?

As an experienced website operation expert, I have accumulated rich experience in the practice of AnQiCMS.Today, we will delve into a question that many content creators and operators are concerned about: How many Tag tags can I add to a document?In the world of AnQiCMS, document tags are far more than just a collection of keywords; they are powerful tools for connecting content, optimizing SEO, and enhancing user experience.

2025-11-06