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

Calendar 👁️ 51

In the flexible world of AnQiCMS, the custom parameters (Custom Parameters) of the content model (Content Model) provide website operators with a great degree of 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 details page may need to display information such as "model number", "color options", "material" and so on, while a technical article may require fields such as "author", "publish date", "references" and so on.

So, after we carefully configure the custom parameters for these documents in the background, how can we elegantly display them in the front-end template, especially when we need to iterate over and display each parameter?Name(Name) andValueWhat about the value? Anqi CMS provides a specialarchiveParamstag, which is like a bridge, perfectly connecting the flexible configuration of the backend with the dynamic display of the frontend.

Custom parameters in AnQi CMS: the cornerstone of rich content

Further inarchiveParamsBefore the label, let's briefly review the positioning of custom parameters in AnQiCMS.When you create a new content model (such as a "product model"), in addition to the system-defined fields, you can also add dedicated custom fields according to business requirements.These fields can be single-line text, numbers, multi-line text, single selection, multiple selection, or drop-down selection and other types.Once defined, when you publish a document of the "product" type, you can fill in specific values for these custom fields.These flexible custom parameters allow AnQiCMS to easily handle various complex website content structures.

archiveParamsTags: unlock the display power of custom parameters

archiveParamsTags are designed to facilitate the retrieval and display of custom parameters bound to specific documents. Their core function is to allow you to iterate over all custom parameters of a document and extract their names(Name)and its corresponding value(Value)

Let's see its basic usage:“

{% archiveParams params %}
    {% for item in params %}
        <p><strong>{{ item.Name }}:</strong> {{ item.Value }}</p>
    {% empty %}
        <p>该文档暂无自定义参数信息。</p>
    {% endfor %}
{% endarchiveParams %}

In this code block:

  • {% archiveParams params %}: We declare a variable namedparamswhich will carry the current document (by default, if not specifiedidThe collection of all custom parameters for the current detail page document.
  • {% for item in params %}This line of code starts a loop,itemThe variable represents an independent custom parameter in each iteration.
  • {{ item.Name }}In the loop, throughitem.NameWe can get the current custom parameter name set in the background configuration (such as "product model", "color").
  • {{ item.Value }}:Anditem.ValueIt will display the specific "parameter value" you fill in the background (for example, "Snapdragon 888", "black").
  • {% empty %}This is a very considerate feature, if the current document has no custom parameters, orparamsthe variable is empty, then the content of the block will be displayedemptyto avoid blank pages or errors on the page.

Label parameter details: finer control

archiveParamsLabels also provide some parameters to allow finer control of their behavior:

  • id: By default,archiveParamsThe current document page's custom parameters will be automatically retrieved. But if you need to get the parameters of a specified document, you canid="文档ID"specify it explicitly. For example:{% archiveParams params with id="123" %}The parameters of the document with ID 123 will be obtained.
  • sortedThis parameter determines:paramsThe data structure returned by the variable.
    • sorted=true(Default value):paramsIt will be an array of objects arranged in an order defined by the backend. In this case, you can use it as shown in the exampleforLoop throughitem.Nameanditem.ValueThis is the most commonly used scenario
    • sorted=false:paramsIt will be unorderedmap(Pair) object. At this point, if you know the custom parameter's "call field" (the English name defined in the content model, such asprocessor), you can directly pass through{{ params.processor.Name }}and{{ params.processor.Value }}Come to visit a specific parameter, but this way you cannot directly perform a simple loop traversal.
  • siteId: If you have enabled the AnQiCMS multi-site management feature and need to call data from other sites, you cansiteId="站点ID"specify.

Practice exercise: Build a parameter list for the product detail page

Assuming we are building a product detail page for an e-commerce website that sells electronic products, and in the product model in the background, we have defined custom parameters such as 'processor', 'memory', 'storage', 'screen size', and so on.Now, we hope to display these parameters in a sidebar or a dedicated area on the product detail page.

Here is an implementation example in the template:

<div class="product-specifications-section">
    <h4 class="section-title">产品技术参数</h4>
    <ul class="spec-list">
        {% archiveParams productSpecs %}
            {% for spec in productSpecs %}
                <li class="spec-item">
                    <span class="spec-name">{{ spec.Name }}:</span>
                    <span class="spec-value">{{ spec.Value }}</span>
                </li>
            {% empty %}
                <li class="no-specs-info">该产品暂未提供详细技术参数。</li>
            {% endfor %}
        {% endarchiveParams %}
    </ul>
</div>

Through this concise code, no matter how many custom parameters you add to the product in the background, as long as they are filled in correctly, the front-end page can automatically and dynamically list their names and values one by one.This not only greatly improves the efficiency of content management, but also makes the display of website content more flexible and rich in layers.

Optimization and注意事项

In practical applicationarchiveParamsWhen labeling, there are some points to note:

  • Front-end style is crucial:The tag itself is only responsible for outputting data, how to make these parameters beautiful and easy to read for users, which still depends on CSS styles. For example, you can setproduct-specifications-section/spec-list/spec-itemAdd the corresponding styles.
  • Plan the backend first:A good front-end display cannot be separated from clear back-end planning.When defining custom parameters, it is recommended to use intuitive 'parameter names' and meaningful 'call fields', which will make template creation and content management easier.
  • Utilize{% empty %}:Always useemptyblock to handle cases without custom parameters, which can effectively improve user experience and avoid the embarrassment of missing page content.

ByarchiveParamsTags, AnQiCMS makes it easy to display custom parameters, whether it is to build complex product lists or rich article detail pages,

Related articles

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 is the `archiveParams` tag's `id` parameter used to retrieve custom fields of a specific document?

As an experienced website operation expert, I am happy to give you a detailed explanation of how the `archiveParams` tag's `id` parameter is used to obtain custom fields of specific documents in AnQi CMS.The AnQi CMS, with its flexible content model and powerful template tag system, provides great convenience for content operations.Grasp the essence of these tags, which can make your website content display more personalized and greatly increase operational efficiency.

2025-11-06

How to use the `archiveParams` tag to display all custom parameters of the current document in AnQiCMS template?

AnQiCMS template's `archiveParams` tag: easily display all custom parameters of the document As a senior website operations expert, I am well aware that in a content management system, how to flexibly display and utilize the various properties of documents is crucial for website customization and functional expansion. AnQiCMS, as an efficient and customizable content management system, provides a rich and powerful set of template tags, among which the `archiveParams` tag is the core tool to unlock the powerful features of document custom parameters.

2025-11-06

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 call the `archiveParams` tag individually in AnQiCMS template to get custom document parameters with a specific name?

In the rich feature treasure trove of AnQiCMS, the content model and custom document parameters are undoubtedly the foundation of its flexibility and powerful extensibility.As an expert in website operations, 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 technique in the AnQiCMS template: how to call the `archiveParams` tag individually to obtain custom document parameters with a specific name.Introduction

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