How to display extra field data under a custom content model in Anqi CMS?

Calendar 👁️ 70

In AnQi CMS, the flexibility of the content model is a major highlight of the project, allowing us to create and manage various types of content structures according to the actual business needs.Whether it is an article, product, event, or any other information that requires specific fields to describe, it can be easily achieved through a custom content model.After we add exclusive additional fields to these models, the next natural step is how to accurately and beautifully display this valuable data on the website front end.

This is not a complex task, Anqi CMS provides intuitive and convenient template tags to complete it.We will delve into the creation of custom fields and how to call and display this data on different types of pages (such as detail pages, list pages) step by step.

Define and configure custom fields

Before starting the presentation, we first need to ensure that the additional fields under the custom content model have been correctly defined and configured.This is like preparing a dedicated 'information table' for our content, with each additional field being a specific column in the table.

You can access the 'Content Management' menu in the Anqi CMS backend and then select 'Content Model' to enter the model management interface.Here, you can choose to edit the existing content model, such as 'Article Model' or 'Product Model', or create a new content model as needed.

In the content model editing interface, find the "content model custom field" section.In here, you can add new fields according to your business needs.Each field must be set to the following key information:

  • Parameter name:This is the Chinese name displayed in the background interface, which is convenient for you to understand its purpose when managing content, such as 'article source', 'author email'.
  • Call field:This is the unique identifier used to call this field data in the front-end template,Please use lowercase English lettersMake sure it is descriptive, for examplesource/authorEmail. This name is case-sensitive, so it needs to be strictly matched when used.
  • Field type:AnQi CMS provides various field types to meet different data storage needs, including:
    • Single-line text:Applicable to short text, such as author name, external link.
    • Number:Only input numbers, such as price, stock quantity.
    • Multi-line text:Applicable to longer text, such as product features, detailed introduction.
    • Single choice, multiple choice, dropdown choice:Data applicable to preset options, such as product color, size. These options need to be filled in one per line in the "default value".
  • Mandatory?:Determine whether the user must fill in this field when publishing content.
  • Default:If the field has a default value and it is not filled in when publishing the content, the system will automatically use the value set here. For selection fields, this is where the options to choose from are set.

After completing these settings, when you publish or edit content under the corresponding model, you will see these custom fields appear in the folded area of "Other Parameters", waiting for you to fill in the data.

Display custom field data in the front-end template

The name of the custom field "callback field" is the key we use to retrieve data in the template. The Anqi CMS template engine supports syntax similar to Django, using double curly braces{{ 变量名 }}Output variables and use{% 标签 %}Execute logic operations.

1. In the document detail page (archiveDetail) or category detail page (categoryDetail) display

When you are on the detail page of a single document (such as an article, product) or the detail page of a category, it is usually usedarchiveDetailorcategoryDetailTag to get the detailed data of the current page. There are several common ways to display custom field data:

Call directly by field name:This is the most direct way. If your custom field's "call field" isauthor, then you can call it like this in the document detail page:

<div>作者:{% archiveDetail with name="author" %}</div>

Or, if you have already assigned the document detail data to a variable (for examplearchive), you can also access it directly using the dot notation:

<div>作者:{{ archive.author }}</div>

For the category detail page, the logic is similar. If the calling field of the custom field iscustomBanner, you can in thecategoryDetaillabel:

<div>自定义Banner:<img src="{% categoryDetail with name='customBanner' %}" alt="分类自定义图片" /></div>

Traverse all custom fields:Sometimes, you may want to dynamically display all the defined additional fields and their values on the page without specifying them one by one.archiveParamsThe tag is created for this purpose, it can retrieve all custom parameters of the current document or a specified document.

{% archiveParams params %}
    <div>
        <h3>额外参数信息:</h3>
        {% for item in params %}
            <div>
                <span>{{ item.Name }}:</span>
                <span>{{ item.Value }}</span>
            </div>
        {% endfor %}
    </div>
{% endarchiveParams %}

Hereitem.NameIt corresponds to the "parameter name" you set in the background (displayed in Chinese), anditem.ValueThe actual data you enter during content editing.

For category detail pages, you can use.categoryDetailCombinename="Extra"To iterate through custom fields:

{% categoryDetail extras with name="Extra" %}
    <h3>分类额外信息:</h3>
    {% for field in extras %}
        <div>{{ field.Name }}:{{ field.Value }}</div>
    {% endfor %}
{% endcategoryDetail %}

To process multiline text and HTML content:If your custom field type is 'Multiline Text' and you enter content with HTML tags or Markdown formatting, the direct output may cause content escaping, HTML tags may not be parsed by the browser, or Markdown formatting may not render correctly.

  • For ordinary HTML content, you need to use|safea filter to tell the template engine that this content is safe and does not need to be escaped:
    
    <div>详细介绍:{{ archive.descriptionDetail|safe }}</div>
    
  • If the content is in Markdown format, you need to use|rendera filter to render it into HTML, then use|safeFilter:
    
    <div>Markdown内容:{{ archive.markdownContent|render|safe }}</div>
    

to handle multiple choice or group chart fields:If your custom field is a 'Multiple Choice' or a 'Gallery' type used for uploading multiple images, they will usually be returned as an array object in the template. At this time, you need to useforLoop to traverse and display each value.

Assuming you have defined a variable namedproductImagesgroup chart field:

{% archiveDetail productImgs with name="productImages" %}
    <ul class="product-gallery">
        {% for imgUrl in productImgs %}
            <li><img src="{{ imgUrl }}" alt="产品图片" /></li>
        {% endfor %}
    </ul>
{% endarchiveDetail %}

or directly fromarchivevariable and loop through:

<ul class="product-gallery">
    {% for imgUrl in archive.productImages %}
        <li><img src="{{ imgUrl }}" alt="产品图片" /></li>
    {% endfor %}
</ul>

2. In the document list page(archiveList) display

In the document list page, you usually usearchiveListTags cycle through multiple articles or products. In each cycle,itemYou can directly access its custom field data through the dot.

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
        <div class="article-card">
            <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
            <p>作者:{{ item.author }}</p> {# 直接访问自定义字段 'author' #}
            <p>文章来源:{{ item.source }}</p> {# 直接访问自定义字段 'source' #}
            <div class="summary">{{ item.Description }}</div>
            {% if item.productImages %} {# 检查组图字段是否存在 #}
                <div class="thumb-preview">
                    <img src="{{ item.productImages[0] }}" alt="封面图" /> {# 显示第一张图片 #}
                </div>
            {% endif %}
            <span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
        </div>
    {% empty %}
        <p>当前列表没有任何内容。</p>
    {% endfor %}
{% endarchiveList %}

Please note that you can directly access custom fields (such asitem.author) is usually the most efficient way. If you still need to access all custom fields within a loop and iterate over the tags, you must pass the current item's ID:archiveParams标签遍历,则需要传入当前列表项的ID:

`twig {% archiveList archives with type=“list” limit=“5” %}

{% for item in archives %}
    <div class

Related articles

How to specify and display different templates for specific documents or categories?

AnQi CMS provides a flexible and powerful template management mechanism that allows users to specify and display unique templates for documents, categories, and even single pages based on different content types or specific needs.This feature greatly enhances the personalized display capabilities and operational efficiency of the website content.Understanding the significance of template customization In website operations, the diversity of content often requires different presentation methods.An in-depth technical article may require a concise and clear layout so that readers can focus on the content itself;A promotional activity page may require prominent visual elements and call-to-action buttons

2025-11-07

How to display the page views and comment count of the document?

In website content operation, accurately displaying the document's page views and user comment numbers is a key indicator of the popularity and user activity of the content.AnQiCMS provides flexible and intuitive template tags, helping us easily display these important data in the various corners of the website without delving into complex backend logic.### Show view count and comment number on document detail page When you want to display the current view count and total number of comments on a single document detail page (such as an article, a product detail page), AnQiCMS's

2025-11-07

How to customize the display of thumbnail and cover images for articles or products?

In website content operation, the visual appeal of images is crucial.Whether it is to show the essence of an article or highlight the highlights of a product, a suitable thumbnail and cover image can greatly enhance the user experience and have a positive impact on the spread of content.AnQiCMS (AnQiCMS) offers rich and flexible features, allowing us to easily customize the display of images for articles or products according to specific needs.This article will introduce how to manage and display thumbnails and cover images in AnQi CMS from two aspects: background configuration and template calling.--- ### One

2025-11-07

How to display the list of recommended content related to the current document in AnQi CMS?

When operating a website, we often hope that users can smoothly find more interesting content after reading a wonderful article.This not only extends the user's stay time and reduces the bounce rate, but is also an effective way to enhance the overall value of the website's content and SEO performance.AnQi CMS knows this, and therefore it provides a variety of flexible ways to display the recommended content list related to the current document, helping us better guide users. To implement recommendations for related content, we first need to understand how Anqicms defines 'related'.In system design, "related" can be reflected at several levels

2025-11-07

How to display single page content on the front end of a website (such as About Us, Contact Us)?

In website operation, single-page content like "About Us" and "Contact Us" is indispensable, as it carries important functions such as displaying corporate image, providing contact information, or stating service terms.For friends using AnQiCMS, it is actually a very direct and flexible thing to beautifully display these single-page contents on the website front end. ### Single Page Content Management Overview Firstly, we need to create and manage these single pages in the AnQiCMS backend system.In the left navigation bar of the background, you can find the "Page Resources" menu

2025-11-07

How to display and manage the display of images and video multimedia resources?

In website operation, high-quality multimedia content is the key to attracting visitors and improving user experience.AnQiCMS (AnQiCMS) is well-versed in this, providing comprehensive features to help users easily manage and flexibly display images and videos on their websites.From unified resource library to intelligent optimization settings, AnQiCMS makes multimedia management efficient and convenient. ### One, Core Multimedia Management Center: Image Resource Management Anqi CMS gathers all uploaded images and video resources into a centralized "Image Resource Management" module.This is not only the place where you store your materials

2025-11-08

How to implement the switching display of multilingual website content?

In today's globalized digital environment, making a website support multiple language display is no longer an option, but a necessity for many enterprises and content operators to expand international markets and improve user experience.AnQiCMS (AnQiCMS) took this into consideration from the very beginning, integrating powerful multilingual support features to help us easily switch between different language displays on the website.How can we specifically operate to enable multilingual content switching capabilities for our Anqi CMS website?This can mainly be found in the system language package

2025-11-08

How to format and display timestamps as readable dates or times in templates?

In the daily operation of AnQi CMS, we often need to handle various data, among which time information is undoubtedly the most common and important kind.Whether it is the publication date of the article, the update time, or the specific moment of user comments, these time data are usually stored in the form of timestamps.However, the original timestamp is not intuitive for ordinary users; they are more like a string of meaningless numbers.At this point, it becomes particularly important to convert these timestamps into a date or time format that is easy to understand.The Anqi CMS template system uses a syntax similar to the Django template engine

2025-11-08