How to call the `archiveParams` tag individually in AnQiCMS template to get custom document parameters with a specific name?

Calendar 👁️ 59

In the rich feature treasure of AnQiCMS, the content model and custom document parameters are undoubtedly the foundation of its flexibility and powerful extensibility.As a website operations expert, I am well aware of how to efficiently and accurately call these custom parameters in templates, which is crucial for achieving personalized content display and optimizing operational efficiency.Today, let's delve deeply into a powerful and often overlooked trick in the AnQiCMS template: how to call it individuallyarchiveParamsLabel to obtain custom document parameters with a specific name.

I. Introduction: Deciphering the value of AnQiCMS custom document parameters.

AnQiCMS can become the preferred choice for many small and medium-sized enterprises and content operation teams, largely due to its highly customizable content model.By custom fields, we can add unique properties to articles, products, or any other content type, such as adding 'color', 'size', 'material' for products, or 'author bio', 'original link' for articles, etc.These custom parameters allow our content to go beyond fixed fields, enabling it to change according to business needs, greatly enriching the dimensions of information display.

In the AnQiCMS template system,archiveParamsThe tag plays a core role, it is specifically used to extract these custom parameters from the document.We usually use a loop to iterate through all the parameters to display them, but in some cases, if we only want to get the value of a parameter with a specific name and then perform other operations, the traditional loop method is not direct enough. 幸运的是,archiveParamsThe tag provides a more refined control method, allowing us to directly access specific custom parameters as if accessing object properties.

Second,archiveParamsThe core mechanism of the tag and two modes of invocation.

archiveParamsThe tag is used in AnQiCMS templates to obtain all custom parameters of the current document (or specified document). To understand how to call a specific named parameter individually, we first need to understand its two main data acquisition modes:

  1. Default mode (sorted=true): This isarchiveParamsThe default behavior of the tag. When not specifiedsortedthe parameter or set it totrueit will return an ordered array object. Each element in this array represents a custom parameter, includingName(Parameter name, such as "Product Color") andValue(Parameter value, such as "red"). This pattern is very suitable for looping to display all custom parameters, such as listing all specifications on a product detail page.

  2. Unordered Map mode (sorted=false)This is the main topic we are discussing today. WhenarchiveParamsLabel settingssorted=falseWhen it will no longer return an ordered array, but an unordered Map (which can be understood as a set of key-value pairs). The "key" (key) is exactly what we define in the background content model for custom fields "Field invocationThe name is usually in English lowercase camel case or underscore naming, while the value is an object containing the custom parameter'sNameandValue.

    In the background content model, when we add a custom field to a certain model (such as "product model"), it is required to fill in the "parameter name" (such as "product color") and the "called field" (such asproductColorThis "call field" is the key identifier we use to directly access specific parameters in unordered Map mode.

Chapter 3: Precision Strike: Calling Specific Named Custom Document Parameters Individually

Now, we focus on how to utilizearchiveParamsThe unordered Map pattern, enabling precise invocation of custom parameters for specific names.

Core strategy: utilizingsorted=falseParameter

When we willarchiveParamslabel'ssortedthe parameter tofalseWhen, its internal returned data structure will become a Map.This means that we can access elements in the Map just like accessing properties of a JavaScript object using dot notation.

Code practice: Implement step by step.

Let's demonstrate through a specific example.

First step: Assume backend configurationTaking the 'Product Model' as an example, assuming that in the AnQiCMS backend content model, we have added the following custom fields for the product:

  • Parameter Name: Product ColorField invocation:productColor
  • Parameter Name: Material of the productField invocation:productMaterial
  • Parameter Name: Suitable scenarioField invocation:applicationScene

Second step: Template invocation example

Now, in the product detail page template (for exampleproduct/detail.htmlIn this case, if we want to get the values of the specific parameters "Product Color" and "Application Scenario" without traversing all parameters, we can write the template code like this:

{# 在产品详情页模板中调用,假设当前文档就是产品 #}
{% archiveParams productDetails with sorted=false %}
    <div class="product-specs">
        {% if productDetails.productColor %} {# 建议进行if判断,确保字段存在 #}
            <p><strong>产品颜色:</strong> {{ productDetails.productColor.Value }}</p>
        {% endif %}

        {% if productDetails.applicationScene %} {# 同上,判断字段是否存在 #}
            <p><strong>适用场景:</strong> {{ productDetails.applicationScene.Value }}</p>
        {% endif %}

        {# 如果需要获取参数名本身,也可以这样: #}
        {# <p>{{ productDetails.productColor.Name }}: {{ productDetails.productColor.Value }}</p> #}
    </div>
{% endarchiveParams %}

In this code block:

  • We first use{% archiveParams productDetails with sorted=false %}Get all custom parameters and store them in a map namedproductDetailsmap variable.
  • Then, throughproductDetails.productColor.ValueandproductDetails.applicationScene.ValueSuch dot syntax, we directly locate and extract the parameter values of "product color" and "application scenario".
  • {% if ... %}Judging is a good practice that can avoid unnecessary blank lines or errors in template rendering when a custom field is not present in some documents.

witharchiveDetailThe differences and advantages of tags.

You may notice that,archiveDetailTags can also directly obtain the value of a single custom field, for example:{% archiveDetail with name="productColor" %}. This method is indeed more concise, especially when you only need to obtain a specific field'sValue.

However,archiveParams(sorted

Related articles

How to use the `archiveParams` tag to dynamically display the product specification parameter list on the product detail page?

In the era where content is king, an efficient and flexible content management system is crucial for a company's online operations.AnQiCMS (AnQiCMS) is an advanced enterprise-level content management system developed based on the Go programming language, with its powerful content model and template tag system, providing us with infinite possibilities for refined content operation.Today, let's delve into a very practical scenario: how to cleverly use the AnQiCMS `archiveParams` tag to dynamically display a rich variety of product specification parameter lists on the product detail page

2025-11-06

How to loop through and display the `Name` and `Value` of custom parameters using the `archiveParams` tag in AnQiCMS templates?

In the flexible world of AnQiCMS, the custom parameters (Content Model) provide website operators with great freedom, allowing us to break through the limitations of traditional titles, content, and summaries, and add personalized data fields for different types of documents (such as articles, products, cases, etc.). For example, a product detail page may need to display information such as 'product model', 'color options', 'material', etc., while a technical article may require fields such as 'author', 'publication date', 'references', etc.

2025-11-06

In the `archiveParams` tag, what scenarios are `sorted=true` and `sorted=false` applicable to?

As an experienced website operation expert, I know that how to flexibly use template tags to display content in such an efficient content management system as AnQiCMS is the key to operation success.Today, let's delve into how the `archiveParams` tag's `sorted=true` and `sorted=false` parameters can have an effect in specific scenarios.Anqi CMS, with its concise and efficient architecture, provides great convenience for content creators and operators.

2025-11-06

In AnQiCMS, how does the `sorted` parameter of the `archiveParams` tag control the output order of custom parameters?

AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides great freedom in content display.Among them, the custom parameter function allows website operators to add unique attributes to content models such as articles, products, etc. according to their actual business needs, such as product specifications, author information, source channels, etc.How to elegantly display these custom parameters in the front-end template, especially the clever use of the core parameter `sorted`, is indispensable.

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

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 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

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