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

Calendar 👁️ 59

In Anqi CMS, content management is not limited to preset fields such as titles and content, but can also be enriched and expanded through 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 frontend template is a common requirement in template creation.This article will deeply explore how to usearchiveParamsLabel, flexibly retrieve and display the custom parameters of the document.

A brief review of setting custom parameters

Further inarchiveParamsBefore the label, let's quickly review the settings of custom parameters.In AnQi CMS backend, you can enter the 'Content Management' module under the 'Content Model' settings to select or create a content model.In here, you can add various types of custom fields, such as single-line text, numbers, multi-line text, single selection, multiple selection, dropdown selection, and more.These fields are what we call 'custom parameters', which allow each document to carry more personalized information.

archiveParamsThe core role of tags

archiveParamsThe tag is a tool used specifically in Anqi CMS template to obtain custom parameters for the current document or a specified document.It can provide all the custom fields configured for the document in the background to the front-end template programmatically, greatly enhancing the flexibility and expressiveness of the template.

This label usually needs to be wrapped in{% archiveParams ... %}and{% endarchiveParams %}Between, used to define a variable to hold the parameter data obtained.

archiveParamsThe key parameters of the

archiveParamsThe tag provides some parameters to help you accurately obtain the required data:

  • idThis parameter is used to specify the document ID you want to retrieve. If you use it in the document detail pagearchiveParamstag and do not specifyidThe parameter, it will default to get the document parameters of the current page. If you want to get the parameters of other documents, you need to explicitly specify its ID, for exampleid="10".
  • sortedThis is a very critical parameter, which determines the returned data structure.
    • Whensorted=trueWhen set to the default value,archiveParamsWill return onean ordered array of objectsEach element in the array is a containing.NameandValueobject, with the properties.Nameis the display name of the custom field,ValueThis is the corresponding value. This pattern is suitable for scenarios where you want to iterate and display all custom parameters of the document.
    • Whensorted=falsethen,archiveParamsWill return oneUnordered Map (key-value pair) object. This Map's key is the 'callback field' of the custom field (defined in the backend content model), and the value is a container that includesNameandValueThe object of properties. This pattern is suitable when you already know the custom field's call name and want to directly access specific parameters.
  • siteIdIn a multi-site management environment, if you need to call the document parameters of other sites, you cansiteIdspecify the ID of the target site as a parameter. Usually, this parameter does not need to be filled in.

How to retrieve and display a custom parameter with a specific name?

UnderstoodsortedAfter the difference of parameters, let's look at the two main ways to retrieve them.

Method one: Traverse all custom parameters (sorted=true)

When you want to display all the custom parameters of the document in the document footer, sidebar, or a dedicated "parameter list" area,sorted=trueThe pattern (also the default pattern) is very useful. It returns an array, which you can use convenientlyforto iterate in a loop.

Assuming you have defined custom fields such as "author", "publisher", "ISBN", etc., they will be returned in array form:

{% archiveParams customFields %}
    {% if customFields %} {# 建议添加判断,只有存在自定义参数时才显示 #}
    <div class="custom-params-list">
        <h3>文档额外信息</h3>
        <ul>
        {% for item in customFields %}
            <li>
                <strong>{{ item.Name }}:</strong>
                <span>{{ item.Value }}</span>
            </li>
        {% endfor %}
        </ul>
    </div>
    {% endif %}
{% endarchiveParams %}

In this code block,item.NameIt will display the "parameter name" you set in the background (such as "author"), whereasitem.Valueit will display the corresponding content of the parameter (such as "Zhang San").

Method two: Directly obtain a custom parameter with a specific name (sorted=false)

If you already know the name of a custom parameter's "call field" and only want to display this parameter, sorted=falseThe pattern can help you get it more directly.

For example, you have defined a custom field named "author" (the call field) in the admin content model. You can get its value directly in the following way:

”`twig {% archiveParams paramsMap with sorted=false %}

Related articles

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

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 functionality, allowing you to flexibly add additional information to documents (articles, products, etc.)When you want to obtain these custom parameters in the website front-end template and display them in the fixed order set in the background, the built-in template tags of Anqi CMS can well help you achieve this.

2025-11-08

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

How to determine if the current navigation item is the current page in the `navList` loop?

In website operation, a clear navigation structure is crucial for improving user experience.A good navigation not only helps visitors quickly find the information they need, but also guides users through visual cues (such as highlighting the current page) so that they always know where they are.In AnQi CMS, implementing this feature is quite intuitive and efficient, which is due to its powerful template tag system.

2025-11-08