What is the core function of the `archiveParams` tag in AnQiCMS template?

Calendar 👁️ 56

In the Anqi CMS template world, efficiently and flexibly displaying content is the key to website operation success.We know that a good content management system not only needs to manage standardized information but also needs to adapt to the ever-changing business needs and provide personalized content display.Today, let's delve deeply into a crucial tag in the AnQiCMS templatearchiveParamsIt is the hero behind the scenes that enables highly customized content.

In AnQiCMS templatearchiveParamsWhat is the core role of tags?

archiveParamsThe tag plays the role of a bridge in the AnQiCMS template, it safely and flexibly presents the custom additional parameters for articles (or any document type, such as products) from the backend to the frontend. In short, when you define personalized information such as 'color', 'size', 'author', 'origin', 'product specifications' in the content model of the backend, in addition to standard fields such as title, content, and categories, for articles, products, or other 'documents',archiveParamsThat is the core tool you use to extract and display these custom data on the page.

Imagine if AnQiCMS only allowed displaying fixed titles and content, then when making e-commerce product pages, real estate information pages, or job position detail pages, it would not be able to display those key, differentiated attributes.archiveParamsThe appearance has completely broken through this limitation, endowing the content model with infinite scalability. It allows you to create unique and rich attribute sets for each type of document based on actual business needs, and through this tag, accurately call and layout these information in the front-end template.

The source of these custom parameters is usually the AnQiCMS backendContent modeldefined inCustom fieldFor example, you can add a custom field named "Product Weight" of type "Number" to the "Product Model". When editing a product, you can fill in its weight.archiveParamsThe task is to extract the value of this "product weight" from the background database and provide it for your template.

Deep understandingarchiveParams: Parameters and Usage

archiveParamsThe basic usage of tags is{% archiveParams 变量名称 with 参数... %}...{% endarchiveParams %}It accepts several key parameters to control the way data is retrieved and organized:

  1. idParameter

    • Purpose: Used to specify custom parameters for the document to be retrieved.
    • Usage:id="1".
    • Instructions: Generally, when you use on the document detail pagearchiveParamsthere is no need to specify manuallyidIt will default to getting the document ID of the current page. But if you need to display custom parameters of a specific document on other pages (such as a module on the homepage), you canidSpecify the parameter explicitly.
  2. sortedParameter

    • Function: Determines the data structure of the returned data isOrdered arrayOrUnordered map (Map).
    • Usage:sorted=trueorsorted=false.
    • Description:
      • Whensorted=trueWhen set to the default value,archiveParamsIt will return an ordered array containing custom parameters. Each array element is an object that includesName(Parameter name, such as "color") andValue(Parameter value, such as "red") two properties. This method is very suitable for scenarios where you want to iterate and display all custom parameters, especially when you are not sure about the custom parameters or they may change dynamically.
      • Whensorted=falsethen,archiveParamsIt returns an unordered mapping (similar to a dictionary), where the key is the 'calling field' of the custom field (defined in the background content model, usually in lowercase English), and the value is the content that includesNameandValueThe object. This method has the advantage that if you know the name of a custom parameter call field, you can directly access its value by field name, without traversing, which is more efficient.
  3. siteIdParameter

    • The function: Specify which site's document data to retrieve in a multi-site management scenario.
    • Usage:siteId="1".
    • Instructions: For single-site users, this parameter is usually not required. If you manage multiple AnQiCMS sites and want to call the document parameters of another site in a template of one site,siteIdIt becomes very useful.

Actual application scenarios and code examples

Let us feel through specific code snippets.archiveParamsThe powerful function.

Scenario one: Traverse and display all custom parameters (such as all specifications of the product)This is applicable to the product details page, where you want to list all the features or specifications of the product.

{# 假设我们正在一个文档详情页,并且后台为该文档定义了“颜色”、“尺寸”、“材质”等自定义字段 #}
<div>
    <h3>产品详细参数:</h3>
    {% archiveParams params with sorted=true %} {# 使用默认的 sorted=true 返回有序数组 #}
    <ul>
        {% for item in params %} {# 遍历数组中的每一个自定义参数 #}
        <li>
            <strong>{{ item.Name }}:</strong> {{ item.Value }}
        </li>
        {% endfor %}
    </ul>
    {% endarchiveParams %}
</div>

This code will intelligently traverse all custom fields, regardless of how many you add in the background, the front end can automatically adapt and display them, greatly reducing the cost of template maintenance.

Scenario two: Directly access specific custom parameters (such as obtaining the product's 'author' information')If you know exactly which specific custom field value you need to display, such as the "author" of an article or the "inventory" of a product.

{# 方法一:通过 archiveParams with sorted=false 获取映射并直接访问 #}
{% archiveParams customFields with sorted=false %}
    {% if customFields.author %} {# 假设自定义字段的“调用字段”是“author” #}
        <p><strong>作者:</strong> {{ customFields.author.Value }}</p>
    {% endif %}
    {% if customFields.stock %} {# 假设自定义字段的“调用字段”是“stock” #}
        <p><strong>库存:</strong> {{ customFields.stock.Value }}</p>
    {% endif %}
{% endarchiveParams %}

{# 方法二:更简洁的方式,直接使用 archiveDetail 标签(推荐已知字段时使用) #}
{# 当您只需要获取一个或少数几个明确知道名称的自定义字段时,archiveDetail 更加直观和简洁 #}
<p><strong>文章作者:</strong> {% archiveDetail with name="author" %}</p>
<p><strong>商品库存:</strong> {% archiveDetail with name="stock" %}</p>

Here we saw.archiveDetailThe tag can directly retrieve custom fields, it is usually recommended for known and specific fields, because it is more concise in syntax.archiveParamsofsorted=falsemode andarchiveDetailOn obtaining a single known custom field, the function is similar, butarchiveParamsThe advantage lies in being able to provide theNameandValueobject, whilearchiveDetailreturn directlyValue.

Scenario three: Handling custom image groups (such as product multi-image display)Assuming you have defined a custom field "Product Image Group" (call field) in the backgroundproduct_images), it allows uploading multiple images.

{% archiveParams params with sorted=false %}
    {% if params.product_images and params.product_images.Value %} {# 检查是否存在产品图片组及是否有值 #}
        <h3>产品图片展示:</h3>
        <div class="product-gallery">
            {% set imageUrls = params.product_images.Value %} {# 获取图片URL的字符串,通常为JSON格式或逗号分隔 #}
            {% set imageArray = imageUrls | list %} {# 假设后台存储的是JSON格式的字符串数组,这里使用list过滤器将其转换为数组 #}
            {% for imgUrl in imageArray %}
                <img src="{{ imgUrl }}" alt="产品图片">
            {% endfor %}
        </div>
    {% endif %}
{% endarchiveParams %}

This example shows.archiveParamsFlexibility in handling complex custom data (such as image arrays), usually requires combining with AnQiCMS filters (such aslist) to parse and display.

archiveParamsRelationship with other tags

archiveParamsIt is not isolated, it is closely connected to the AnQiCMS ecosystem:

  • Relationship with the Content Model (Content Model): archiveParamsEverything displayed is sourced from the backendContent modeldefined inCustom field. Without the extension of the content model,archiveParamsthere is no flour to cook.
  • witharchiveDetailLabel relationships:As mentioned before,archiveDetailcan be directly accessed throughname="自定义字段名"The way to get the value of a single custom field. When you are only interested in a specific custom field,archiveDetailit is usually more concise. AndarchiveParamsIt is more suitable for scenarios where you need to dynamically traverse all custom fields, or need to access fields.NameandValueFor more precise control over objects.
  • witharchiveFiltersLabel relationships: archiveFiltersUsed to generate filtering conditions on the list page, the underlying data also comes from the 'filterable parameters' configured in the content model.archiveParamsIt is aimed at individual documents, displaying their specific parameter values.

Summary

archiveParamsThe tag is an indispensable tool for the AnQiCMS content operation experts.It gives AnQiCMS great content customization flexibility, allowing you to easily display the rich custom parameters defined in the background content model in a user-friendly way on the front end.To enhance the information density of the product detail page or to achieve highly personalized display of specific document types, proficiency in masteringarchiveParamsThe use of, can make your AnQiCMS website content more attractive and more in line with business needs.


Frequently Asked Questions (FAQ)

  1. When should I usearchiveParamsWhen to usearchiveDetailto get custom fields?
    • UsearchiveParams:when you need to iterate and display a documentallormostWhen customizing fields (especially when you are unsure about the fields, or the fields may change dynamically), or

Related articles

How to output system information configured in the AnQiCMS template, such as website name, Logo, and filing number?

In the flexible world of AnQiCMS, elegantly presenting the system-level information configured in the background to the front end of the website is a core skill that every website operator and template developer needs to master.As an experienced website operations expert, I know that these seemingly trivial details are invaluable for enhancing brand image, optimizing user experience, and meeting regulatory requirements (such as displaying the filing number).Today, let's delve deeply into how to output these valuable background information in the AnQiCMS template in a natural and smooth manner. AnQiCMS

2025-11-06

How to define and call the `macro` macro function in the AnQiCMS template to create reusable code snippets?

In the process of website operation and development, we always encounter the need to repeatedly write similar code segments, such as unified article card styles, product information display modules, or form elements with specific interactions.If you start from scratch every time, it is not only inefficient, but also makes maintenance a nightmare.AnQi CMS is well-versed in this, its powerful template engine provides us with the 'macro' macro function, a tool aimed at helping developers and operators easily create reusable code snippets

2025-11-06

How to implement template inheritance with the `extends` tag and overwrite specific blocks of the parent template?

As an experienced website operations expert, I deeply understand that a flexible and efficient template system is crucial for the long-term development of a website.In AnQiCMS (AnQiCMS), it draws on the powerful capabilities of the Django template engine, allowing you to manage the website interface in a simple and logical way.Today, we will focus on one of the core features - the `extends` tag, and delve into how it implements template inheritance, allowing us to accurately rewrite specific blocks of the parent template.

2025-11-06

How to implement code reuse and pass additional variables using the `include` tag in template development?

As an experienced website operations expert, I am well aware of the importance of template development efficiency and code maintainability for a website in my daily work.AnQiCMS (AnQiCMS) relies on its efficient architecture based on the Go language and the Django-style template engine, providing us with powerful content management capabilities.Today, let's delve deeply into a tool that can significantly improve efficiency and code reuse in Anqi CMS template development, namely the `include` tag, especially how it helps us achieve code reuse and flexibly pass additional variables.

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

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

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