How to retrieve all custom parameters of a document in an Anqi CMS template and display them in a fixed order?

Calendar 👁️ 69

In website content management, we often need to define unique attributes for different types of information to meet the diverse display needs of the website.The AnQi CMS provides powerful custom parameter functions, allowing you to flexibly add extra information to documents (articles, products, etc.)When you want to retrieve these custom parameters in the website front-end template and display them in the fixed order set in the background, the template tags built into Anqicms can well help you achieve this.

Understand the custom parameters of the document

The AnQi CMS allows you to create dedicated custom fields for different document types (such as articles, products) through the content model.These fields can include authors, sources, specifications of specific products, event times, etc.These custom parameters have the advantage of not only enriching the document information, but also allowing flexible definition of field types (such as single-line text, numbers, multi-line text, single choice, multiple choice, dropdown selection, etc.), greatly enhancing the flexibility of content management and the adaptability of the website.

Core Tool:archiveParamsTag

To obtain all the custom parameters of a document in the template and ensure that they are displayed in the order you have configured in the background, we need to use a dedicated tag provided by the Anqi CMS template engine—archiveParams. This tag is designed to obtain additional parameters of the document, particularly good at handling ordered parameter lists.

How to usearchiveParamsTag

archiveParamsThe basic usage of the tag is to wrap it in a block.{% archiveParams params %}and{% endarchiveParams %}Here, paramsIs a variable name you define, it is used to store all the custom parameters obtained.

By default,archiveParamsThe tags will be returned in the order you set in the "Content Model" backend, a list containing each custom parameter. Each parameter is an object containing two main properties:

  • NameIt indicates the display name of the custom parameter (for example, 'article author', 'product model').
  • ValueIt indicates the specific value of the custom parameter (for example, "Zhang San", "X-Pro 2023").

We will illustrate in detail how to use this tag in a template through an example.

Practice in the template

Assuming you have already defined custom parameters such as "Product Model", "Color", "Material", etc. for a content model in the background.Now, you would like to display these parameters on the product detail page.

You can use the template file in the product detail page, usually{模型table}/detail.htmlor add the following code snippet to a custom document template

{# 假设您正在产品详情页,并且当前文档对象已被正确加载 #}

<div class="product-specs">
    <h3>产品参数</h3>
    {% archiveParams productParams %} {# productParams 是您自定义的变量名 #}
        {% if productParams %} {# 检查是否存在自定义参数 #}
            <ul>
                {% for item in productParams %}
                    {# 遍历每一个自定义参数,item.Name 是参数名称,item.Value 是参数值 #}
                    <li>
                        <strong>{{ item.Name }}:</strong>
                        <span>{{ item.Value }}</span>
                    </li>
                {% endfor %}
            </ul>
        {% else %}
            <p>暂无其他产品参数信息。</p>
        {% endif %}
    {% endarchiveParams %}
</div>

In this code block:

  1. We first use{% archiveParams productParams %}tags to retrieve all custom parameters of the current document, and assign them to a variable namedproductParams.
  2. {% if productParams %}Check if there are any custom parameters present, to avoid displaying an empty list when there are none.
  3. {% for item in productParams %}Loop throughproductParamseach parameter in the variable. SincearchiveParamsBy default, it is returned in the order set by the background, so hereitemIt will appear in the order defined in the content model.
  4. Inside the loop,{{ item.Name }}The parameter name (such as 'Product Model') will be displayed, whereas{{ item.Value }}the specific value of the parameter (such as 'AnQiCMS Pro') will be displayed.

In this way, you can not only easily obtain all the custom parameters of the document, but also ensure that they are presented to the user in a structured and orderly manner. This is particularly important for scenarios where product specifications, technical documents, and other information display sequences need to be strictly followed.

Get custom parameters of the specified document

The above example defaults to retrieving the parameters of the currently browsing document. If you need to getother specified documentCustom parameters, for example, in a related recommendation module, you can useidparameter to specify the document ID:

{# 假设您要获取 ID 为 123 的文档的自定义参数 #}
<div class="related-document-specs">
    <h4>相关文档(ID: 123)参数</h4>
    {% archiveParams specificDocParams with id="123" %}
        {# 同样可以通过循环遍历 specificDocParams 来显示其内容 #}
        {% for item in specificDocParams %}
            <p>{{ item.Name }}: {{ item.Value }}</p>
        {% endfor %}
    {% endarchiveParams %}
</div>

Emphasis on parameter sorting

archiveParamsLabels are returned by default in the order you have configured in the "Content Model" on the backend. This means you do not need any additional settingssorted=true(Although the parameter is mentioned in the document, it is usually omitted because it is the default behavior). If you indeed need to access key-value pairs in an unordered manner (for example, by accessing a specific parameter directly by name, without caring about its position in the list), you cansortedthe parameter tofalsebut for the need to display in fixed order, keep default or explicitsorted=trueJust do it.

In summary, AnQi CMS'sarchiveParamsTags are an efficient and intuitive tool that makes it exceptionally simple to display custom parameters in templates, while fully respecting the display order you set in the background, thereby greatly enhancing the efficiency of template creation and the expressiveness of content.


Frequently Asked Questions (FAQ)

  1. Ask: How can I display a specific custom parameter instead of all parameters?Answer: If you only need to display a single custom parameter, you can usearchiveDetailLabel and specify the parameter name. For example, if you have a custom parameter namedproduct_modelyou can directly call it in the template:{% archiveDetail with name="product_model" %}. This method is more direct and does not require looping through all parameters.
  2. Ask: If a custom parameter is not filled in, how can I make it not display?Answer: In a loopproductParamsWhen defining a variable, you can{% for item in productParams %}Add a conditional judgment inside the loop. For example,{% if item.Value %}So that, only whenitem.Valuethere is content, will the name and value of the parameter be displayed.
  3. Ask: Can I get the custom parameters of the document on other pages (such as the list page) besides the document detail page?Yes, you can.archiveParamsTags can be used.idSpecify the ID of any document to retrieve the custom parameters of the document.This means you can call this tag by providing a document ID anywhere you need it (such as within each document item in a list page loop or in a related recommendation block) to retrieve and display the custom parameters of the specified document.archiveParamsThe page loading time may increase, it is recommended to optimize according to actual needs and performance.

Related articles

How to combine the `archiveList` tag with query parameters in the URL to implement dynamic search and filtering?

Build an interactive and easy-to-navigate website on Anqi CMS, with dynamic search and filtering functions being indispensable.`archiveList` tag as the core tool for content output, cleverly combines URL query parameters, and can help us implement a powerful content discovery mechanism, allowing users to easily locate the information they are interested in. ### The core function of the `archiveList` tag The `archiveList` tag is used in AnQi CMS to retrieve and display document lists.

2025-11-08

How to loop through a document list in an Anqi CMS template and output custom parameters for each document?

AnQiCMS provides powerful template customization capabilities, allowing us to flexibly display various content according to the actual needs of the website.When we not only need to loop through the document list but also want to output unique custom parameters for each document, the template tags of AnQiCMS can well help us achieve this.This is particularly important for a content model that has diversified attributes for displaying product details, real estate information, job openings, etc.

2025-11-08

How does the `archiveFilters` tag display the filter list containing the 'All' option?

In website content operation, it is crucial to provide users with convenient and intuitive filtering functions.Especially when your website content structure is complex, containing various attributes and categories, a well-designed filter list can greatly enhance user experience, helping them quickly find the information they need.AnQi CMS provides a powerful `archiveFilters` tag, specifically designed to build this type of filter list based on document parameters.Today, we will delve into how to use this tag, especially how to cleverly add an 'All' option to make your filtering function more perfect and user-friendly.

2025-11-08

How to dynamically generate filter conditions for content models in AnQi CMS templates (e.g., filtering by properties)?

When building and operating a website, providing users with an efficient content filtering function is crucial for improving user experience and content discoverability.AnQiCMS (AnQiCMS) leverages its flexible content model and powerful template tag system to help us easily implement dynamic generation of content model filtering conditions in templates, such as filtering by attributes. ### Content Model and Custom Fields: The Basis of Filtering One of the core strengths of AnQi CMS is its highly flexible content model.

2025-11-08

How to retrieve and display custom document parameters for a specific named using the `archiveParams` tag?

In AnQi CMS, content management is not limited to preset fields such as titles, content, etc., but can also be enriched and expanded by custom parameters.When you set unique custom fields for articles, products, or other content models, how to accurately obtain and display these specific parameter names in the front-end template is a common requirement in template creation.This article will deeply explore how to flexibly obtain and display the custom parameters of the `archiveParams` tag.### Custom parameter setting

2025-11-08

How to build a multi-level category navigation in Anqi CMS template and judge whether each category has subcategories?

In today's increasingly rich website content, a clear and efficient navigation system is crucial for improving user experience and search engine optimization (SEO).Especially for websites with a large amount of content or multiple product categories, multi-level category navigation can help users quickly find the information they need while also showing the structural hierarchy of the website to search engines.Anqi CMS with its flexible and powerful template engine makes it simple and intuitive to build such a navigation.This article will deeply explore how to cleverly construct a multi-level classification navigation in Anqi CMS template, and intelligently judge whether each category contains subcategories

2025-11-08

How to display documents under the current category using the `categoryList` tag without including documents from subcategories?

When building a website with Anq CMS, we often encounter such a need: on a category page, we want to display only the documents that belong to the current category, and not mix in the document content of its subcategories.This is particularly important in scenarios where the content structure is clear and avoids redundancy.Today, let's discuss in detail how to accurately achieve this goal through the template tags of Anqi CMS. ### Understanding AnQiCMS Classification and Document Relationship AnQiCMS has always fully considered the flexibility of content hierarchy from the beginning of its design.A category can have subcategories

2025-11-08

How to use the `navList` tag to create a navigation bar with submenus in the Anqi CMS template?

In AnQi CMS template development, building a functional and user-friendly navigation bar is one of the core tasks of website frontend development.Especially when navigation needs to include multi-level sub-menus, the `navList` tag provided by Anqi CMS can help us efficiently meet this requirement.Understanding the core role of the `navList` tag The `navList` tag is a tool specifically used in the Anqi CMS template to retrieve website navigation data and display it on the page.

2025-11-08