How to call and display the data of the custom model field in the document?

Calendar 👁️ 68

In Anqi CMS, the flexible content model is one of its core advantages, allowing us to create various information carriers such as articles, products, and so on according to different business needs, and define unique properties for them.How to present the data of these personalized fields customized for the document on the front end of the website is a focus of many users.This article will detail the process for you, helping you easily master the custom model fields of Anqi CMS.

Understanding the value of custom model fields

Firstly, let us clarify the importance of custom model fields.In content management, standard fields (such as title, content, and publish time) are often not enough to meet all display needs.For example, a product model may need fields such as "product modelThe AnQi CMS custom model field function is exactly designed to meet this personalized demand.It makes your content structure more in line with actual business, not only improves the fineness of data management, but also provides infinite possibilities for the diversified display of front-end pages.By using it reasonably, you can create website content that is more informative and closer to the needs of users.

Backend settings: Creating and entering custom field data

Before calling the custom field data, we need to complete the field creation and data entry in the background.

  1. Create a custom model field:

    • Enter the Anqi CMS backend, navigate to "Content Management" -> "Content Model".
    • Select the model you want to add a custom field to (such as "article model" or "product model"), click "modify".
    • On the model editing page, find the "Content model custom field" area, click "Add field".
    • Parameter NameThis is the field name displayed in the background for administrators, for example, 'Article Author', 'Product Price'.
    • Field invocation:This is the key name used to call the field data in the template.. Please make sure to use letters, and it is recommended to use camel case naming (for examplearticleAuthor/productPrice). This name will be written to the database and is the unique identifier for data recognition in the template
    • Field typeSelect an appropriate type based on the data characteristics, such as single-line text, numbers, multi-line text, single-choice, multiple-choice, dropdown, etc.This will determine the input method you use when entering data in the background.
    • Mandatory?: Set according to your needs.
    • Default valueCan preset a default value. Save the model after completion.
  2. Enter custom field data:

    • Navigate to 'Content Management' -> 'Document Management' (or the corresponding model list).
    • Click 'Add Document' or edit an existing document.
    • On the document editing page, after selecting the category, the page will load all fields of the model belonging to the selected category.Scroll down, you will see the fields you just customized in the 'Other Parameters' collapse box.
    • Here, you can fill in the corresponding custom field data for each document. This is the content that we will display on the front-end page later.

Template call: How to display custom data on the page

Completed the background setting and data entry, next is the call of the front-end template. The template engine of Anqi CMS is similar to Django syntax, using{{变量}}to output data,{% 标签 %}Come to handle the logic.

1. Call the data of a single known custom field.

When you know exactly which specific custom field data you want to display, you can usearchiveDetailTo get the label. This method is often used on document detail pages.

Suppose you have created a custom field named "Article Author" for the "Article Model" in the background, whose "call field" isarticleAuthor. In the article detail page template, you can call it like this:

{# 直接输出文章作者的自定义字段数据 #}
<div>文章作者:{% archiveDetail with name="articleAuthor" %}</div>

{# 将文章作者的数据赋值给一个变量再输出,方便后续处理 #}
{% archiveDetail authorName with name="articleAuthor" %}
<div>作者:{{ authorName }}</div>

Key point:nameThe value must match the 'Call field' set in the 'Content Model Custom Field' on the backend (including case).

2. Traverse and display all custom field data

Sometimes, you may want to dynamically display all custom fields of a document on a page, or you may not be sure which custom fields there are, in which case you can usearchiveParamstags to iterate over.

In the document detail page template, you can use it like this:

{# 遍历显示当前文档的所有自定义字段 #}
{% archiveParams params %}
<div class="custom-fields">
    {% for item in params %}
    <p>
        <span>{{ item.Name }}:</span>
        <span>{{ item.Value }}</span>
    </p>
    {% endfor %}
</div>
{% endarchiveParams %}

Explanation:

  • {% archiveParams params %}: This line of code will retrieve all the custom field data of the current document and store it inparamsthis variable.
  • {% for item in params %}: Due toparamsis an array (or iterable object) that contains all custom fields, we can useforto iterate over it.
  • {{ item.Name }}:item.NameDisplays the custom field name set in the background (i.e., the Chinese display name).
  • {{ item.Value }}:item.ValueDisplays the specific data value corresponding to the custom field.

Advanced usage: Filter out fields that do not need to be displayedIf you want to iterate through and display most fields but exclude certain specific fields (such as some internally used fields), you can combineifLabel for judgment:

{% archiveParams params %}
<div class="custom-fields">
    {% for item in params %}
        {% if item.FieldName != 'internalNotes' and item.FieldName != 'secretCode' %}
        <p>
            <span>{{ item.Name }}:</span>
            <span>{{ item.Value }}</span>
        </p>
        {% endif %}
    {% endfor %}
</div>
{% endarchiveParams %}

Note: Here is useditem.FieldName, it corresponds to the background settings of 'Call field'.

3. Call custom field data on the document list page

On the document list page (for example, displaying product lists), you may want each product to display its price, model, and other custom fields. In this case, you will usearchiveList.

{# 假设您正在循环产品列表,并希望显示每项产品的产品型号(调用字段:productModel)和价格(调用字段:productPrice) #}
{% archiveList products with type="page" moduleId="2" limit="10" %} {# moduleId="2" 假设是产品模型ID #}
    {% for item in products %}
    <div class="product-item">
        <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
        <p>型号:{{ item.productModel }}</p> {# 直接使用item.调用字段名 #}
        <p>价格:{{ item.productPrice }}</p> {# 直接使用item.调用字段名 #}
        <p>{{ item.Description }}</p>
    </div>
    {% endfor %}
{% endarchiveList %}

Key pointIn

Related articles

How to display the titles and links of the previous and next documents on the document detail page?

In website content operation, it is crucial to provide readers with a smooth reading experience.If a user finishes reading a document and can easily navigate to the previous or next related content, it not only effectively extends the user's stay on the website and increases page views, but also helps search engines better understand the structure and content relevance of the website, thereby having a positive impact on SEO.AnQiCMS (AnQiCMS) has fully considered this point in the design of template functions, providing simple and powerful tags, making it easy to display the title and link of the previous and next documents on the document detail page

2025-11-08

How to display a list of recommended documents related to the current document on the document detail page?

In website content operations, providing users with relevant recommended content not only effectively enhances the depth and duration of page browsing, but also optimizes user experience, indirectly assisting in the SEO performance.In AnQiCMS (AnQi Content Management System), implementing this feature is flexible and direct.Next, we will discuss how to seamlessly integrate and display the recommended document list closely related to the current document on the document detail page. ### Core Value: Why should recommended documents be displayed on the document detail page?

2025-11-08

How to get and display the name and link of the category to which the current document belongs?

On the content detail page of a website, we often hope to clearly display the classification information of the current document, such as the name of the classification and the link to that classification.This not only helps visitors better understand the content structure, but also improves the website's navigation and user experience.Safe CMS provides us with a variety of flexible ways to meet this requirement. We will discuss several methods for obtaining and displaying the category name and link of the current document in the AnQiCMS template, and you can choose the most suitable solution according to your actual template design and requirements.### Method One

2025-11-08

How to implement lazy loading of images in document content to optimize display performance?

## Optimize Website Display Performance: Practical Guide to Implementing Lazy Loading of Images in AnQi CMS In today's internet era, the loading speed of a website is crucial for user experience and search engine rankings.Large image files are often one of the main culprits slowing down website loading speeds. 幸运的是,image lazy loading (Lazy Loading) technology can effectively solve this problem.

2025-11-08

How to filter and display a document list based on specific recommendation attributes (such as 'Headline', 'Recommendation')?

The flexible application of content recommendation properties in AnQiCMS is a key link in enhancing the visibility and user experience of website content.Whether you want to highlight important news on the homepage or recommend selected content in specific sections, AnQiCMS provides a convenient and efficient solution.This article will delve into how to filter and display document lists based on specific attributes such as 'Headlines' and 'Recommendations', helping you better manage and present website content.### Part One: Understanding Recommendation Properties and Their Settings Recommendation properties are a very practical feature in the AnQiCMS content management system

2025-11-08

How to implement keyword search and display results on the document list page?

How to help visitors quickly and accurately find the information they need in the face of increasingly large amounts of website content is the key to improving user experience and website value.AnQiCMS (AnQiCMS) is deeply proficient in content management, providing us with a powerful and flexible keyword search mechanism that allows the document list page to easily implement keyword search and elegantly present the results.

2025-11-08

How to implement multi-condition (such as custom parameters) filtering function on the document list page?

In AnQi CMS, implementing multi-condition filtering functionality on the document list page, especially filtering based on custom parameters, is crucial for improving user experience and helping users quickly find the content they need.AnQi CMS with its flexible content model and powerful template tag system makes this feature highly efficient and intuitive.The entire process can be divided into several core steps: First, define your content model and custom filter fields in the background;Secondly, build the display interface for the filtering conditions in the template; finally, present the filtering results in the document list using list tags.--- ### One

2025-11-08

How to set pagination for a document list and display page navigation?

In modern website operations, setting up pagination for content lists is almost indispensable.It can not only significantly improve the user's browsing experience, avoid the slow loading caused by the long content of a single page, but also help search engines better crawl and index the website content.For friends using AnQi CMS, implementing pagination for the document list and displaying page navigation is a very intuitive and powerful feature.Our AnQi CMS provides flexible template tags, allowing full control over content display.To set pagination for the document list and display page navigation in a friendly manner

2025-11-08