How does the `archiveParams` tag display custom field data for AnQiCMS documents?

Calendar 👁️ 73

In AnQiCMS, the flexibility of website content is one of its highlights, which is attributed to its powerful custom field function of the content model.In addition to standard fields such as article title, content, and publish time, you can also add various custom fields according to business needs for different content models (such as articles, products), such as 'author', 'product model', 'floor area', or 'service features'.These custom fields greatly enrich the expression form of the website content, making it more in line with the actual application scenario.

So, after you have toilfully defined and filled in these custom fields in the background, how can you elegantly display them on the website front-end page? AnQiCMS provides a special template tag for this—archiveParamsIt is the bridge that connects backend custom data with frontend display.

Understand custom fields: backend settings and content entry.

Further inarchiveParamsBefore using tags, let's quickly review the lifecycle of custom fields in the AnQiCMS backend.

Firstly, you need to select or create a model under "Content Management" in the "Content Model", and add custom fields to the model. For example, you can add a field named "Article Source" (the field name is called thesourceThe "single line text" type field.

Next, when you publish documents under "Content Management", select the category you have defined with custom fields, and there will usually be a "Other Parameters" collapsible area at the bottom of the page.After expanding, you will see all the custom fields you have defined for the model.Here, you can fill in the corresponding custom field data for each document, such as entering the article source as 'Zhihu' or 'Original'.

archiveParamsLabel: Get custom field data

archiveParamsThe core function of the label is to help you obtain these additional custom field data on the document detail page (or other pages where specific document custom fields need to be displayed).This tag is very flexible in use, you can choose different parameters according to your specific needs to obtain data.

Its basic syntax structure is usually like this:{% archiveParams 变量名称 with 参数="值" %}

Among them,变量名称Is the temporary variable name you set for the custom field data, for exampleparamsorcustomFields.参数It is used to control the way data is obtained.

Method one: Traverse all custom fields (default and recommended)

When you want to display all custom fields of a document on a page, or are unsure of which fields to display dynamically, you can usearchiveParamsThe default usage. It will return an array object sorted by background, each object containing the Chinese name of the field and its value.

{# 假设当前页面是文档详情页,我们将获取到的自定义字段命名为 params #}
<div>
    <h3>文档附加信息:</h3>
    <ul>
        {% archiveParams params %}
            {% for item in params %}
                <li><strong>{{ item.Name }}:</strong> {{ item.Value }}</li>
            {% endfor %}
        {% endarchiveParams %}
    </ul>
</div>

In this code block:

  • {% archiveParams params %}The tag will retrieve all custom field data of the current document and assign it toparamsVariable.
  • {% for item in params %}Loop throughparamsarray.
  • {{ item.Name }}It will output the parameter name set in the background for custom fields (such as "Article Source").
  • {{ item.Value }}It will output the custom field data entered in the document (for example, "Zhihu").

This method is especially suitable for product detail pages, where you can loop through all product specifications (such as brand, model, size, color, etc.), without needing to preset the calling code for each field, which greatly enhances the reusability of the template.

Method two: Directly retrieve the value of a specific custom field

If you know the name of a custom field's 'call field' and you only need to get its value, not traverse all fields, then how many more concise ways are there.

The most direct way: througharchiveObject access

In the document detail page, you can usually access through directlyarchiveObject (AnQiCMS will automatically assign the detail data of the current document to)archiveUsing a variable to access custom fields. You just need to know the "call field" name defined in the content model.

{# 假设您在内容模型中定义了一个调用字段为 'author' 的自定义字段 #}
<p><strong>作者:</strong> {{ archive.author }}</p>

{# 假设您在内容模型中定义了一个调用字段为 'productModel' 的自定义字段 #}
<p><strong>产品型号:</strong> {{ archive.productModel }}</p>

This method is the most concise, provided that you ensurearchiveThe variable is available, and the 'Call Field' name of the custom field is accurate.

ByarchiveParamscooperatesorted=falseGet specified field

If you need to retrieve multiple specific fields and also want to obtain their 'parameter names', or if the current page is not a direct document detail page, you cannot use it directlyarchiveAn object, then you canarchiveParamslabel'ssortedthe parameter tofalseThus,archiveParamsIt will return an object with the key namedmapAn object, you can access the field data directly by key name.

{# 设置 sorted=false 后,我们将获取到的自定义字段命名为 customFields #}
{% archiveParams customFields with sorted=false %}
    <p><strong>{{ customFields.author.Name }}:</strong> {{ customFields.author.Value }}</p>
    <p><strong>{{ customFields.source.Name }}:</strong> {{ customFields.source.Value }}</p>
    {# 假设 customFields.author 和 customFields.source 存在 #}
{% endarchiveParams %}

In this way,customFields.authoris an object that containsName(such as "author") andValuetwo properties.authorandsourceIt is the name of the 'call field' set for the custom field in the background content model.

Get the custom field by specifying the document ID.

archiveParamsThe tag also supports passing throughidTo specify the custom field data of a specific document to be retrieved instead of the default data of the current page, which is very useful in certain scenarios where cross-document data retrieval is needed.

{# 获取 ID 为 10 的文档的自定义字段 #}
{% archiveParams otherDocParams with id="10" %}
    {% for item in otherDocParams %}
        <p><strong>{{ item.Name }}:</strong> {{ item.Value }}</p>
    {% endfor %}
{% endarchiveParams %}

Summary

archiveParamsThe tag is a very practical feature in AnQiCMS template creation, which is配合内容模型中的自定义字段, allowing you to flexibly manage and display various types of content data. Whether it is dynamically traversing all fields or accurately locating specific fields, archiveParamsAll can provide concise and efficient solutions, helping you build a rich and clear website page.

Frequently Asked Questions (FAQ)

1. Why do I define custom fields in the background?archiveParamsWhen the tag is used, the front-end page does not display any data?

Related articles

How to dynamically set and display the page's Title, Keywords, and Description using the `tdk` tag to optimize SEO?

How to make our content better discovered by search engines and attract more potential users is a continuous challenge in website operation.Among them, the Title (title), Keywords (keywords), and Description (description) these three TDK tags are like a series of 'business cards' on our website in the search engine results page, directly affecting the user's click intention and the understanding of the search engine.AnQi CMS knows this and therefore fully considered the dynamic setting of TDK and SEO friendliness in the initial system design.<h3>Importance of TDK

2025-11-07

How to uniformly display the website's contact information, phone number, and email address with the `contact` tag?

How to efficiently manage and uniformly display a company's contact information, such as contacts, phone numbers, email addresses, and addresses, is a seemingly simple problem that often causes headaches.Imagine if this information were scattered across various pages of a website, and once an update is needed, you would have to search and modify each one individually. This is not only time-consuming and labor-intensive, but it is also prone to omissions or inconsistencies.Fortunately, AnQiCMS (AnQiCMS) provides an elegant solution - the `contact` tag, which helps us easily manage and flexibly display contact information.

2025-11-07

How to call and display the website name, Logo, filing number, and other global configuration information using the `system` tag?

Building a website in Anqi CMS, the basic information of the page, such as the website name, Logo, filing number, copyright information, etc., is an important element in forming the overall style and professionalism of the website.This information often needs to be managed uniformly and flexibly called at various corners of the website.AnQi CMS provides the `system` tag, which is like a central console that allows us to easily call and display these global configuration information.

2025-11-07

How to generate and display a clear hierarchical breadcrumb navigation on the AnQiCMS page using the `breadcrumb` tag?

In website operations, a clear navigation path is crucial for improving user experience and search engine optimization (SEO).When we browse websites, a concise and clear path can help us quickly locate and understand our current position.

2025-11-07

How to build a dynamic filter using the `archiveFilters` tag to display documents that meet specific conditions?

How to help users quickly find the information they are interested in when managing a content-rich website, and improve the access experience, is a challenge that every content operator needs to face.AnQiCMS (AnQiCMS) understands this need and therefore provides a powerful `archiveFilters` tag, allowing you to easily build dynamic filters to provide flexible and diverse search methods for website content. Dynamic filter, as the name implies, is to automatically generate filtering conditions for users to choose from based on different attributes of the content.

2025-11-07

How to get and display the carousel or advertisement images on the homepage using the `bannerList` tag?

In the operation of a website, the homepage carousel or advertisement image is undoubtedly the golden area to attract visitors' attention, convey core information, and promote important content.They not only enhance the visual appeal of a website, but are also crucial for guiding user behavior and promoting content consumption.In Anqi CMS, the functions to implement and manage these carousel or ad images are all concentrated on a powerful and easy-to-use tag —— `bannerList`.

2025-11-07

How to display comments of the `commentList` tag

In website operation, article comments are an indispensable part of enhancing user interaction and activating the community atmosphere.AnQiCMS (AnQiCMS) provides us with a powerful and flexible comment management function, through the clever use of `commentList` tags, we can easily display the comments of articles on the website front-end.This article will delve into the various functions of the `commentList` tag and its practical application in templates, helping you create an interactive and user-friendly comment section.--- ### Core Tag

2025-11-07

In Anqi CMS template, how to center the product title within a fixed area?

In Anqi CMS template, centering the product title within a fixed area is a common layout requirement, which can effectively enhance the visual aesthetics and user experience of the website.Due to the similar Django template engine syntax adopted by AnQi CMS and its good support for frontend styles, we can achieve this goal by combining HTML structure and CSS styles. ### Understanding Anqi CMS Template Structure Firstly, we need to clarify how the product title is called in the Anqi CMS template.

2025-11-07