How to display custom additional field data in the article model to achieve flexible content display?

Calendar 👁️ 70

In AnQi CMS, the flexibility of content is one of its core advantages.We often need to display unique information beyond standard fields such as product SKU codes, release dates, author information, or specific time and location of events.This personalized data, through the custom additional field function, can achieve perfect carrying and management.How to elegantly and flexibly present these carefully entered custom data on the website front-end is a focus of many users.

This article will guide you to deeply understand the display mechanism of custom fields in Anqi CMS, allowing you to control the content display with ease.

Why is it crucial to customize additional fields for content display?

The 'Flexible Content Model' feature of AnQi CMS allows us to create or modify content models based on actual business needs and add an arbitrary number of custom fields. Imagine if your website needs to display a series of electronic products, in addition to product names and descriptions, you might also need:

  • Model Number: A single-line text field
  • Brand: A dropdown selection field
  • WarrantyA numerical field
  • Detailed parameter table (Specification Table)A multiline text or rich text field
  • Product Gallery (Product Gallery)A picture group field

By custom fields, this information can be closely bound with product content, greatly enriching the dimensions of the content.It is more important that it structures the content, providing great convenience for subsequent front-end style design and data calls.

Set custom fields in Anqi CMS background

Firstly, we need to add these custom fields to the content model in the Anqi CMS backend. The operation path is usually:内容管理 -> 内容模型.

Here, you can choose an existing model to modify or create a new one.After entering the model editing interface, you will see the "Content Model Custom Field" area.Click to add field, you need to fill in the following key information:

  1. Parameter NameThis is the field name displayed in the background management interface, for example 'Product Model', 'Warranty Period'.
  2. Field invocationThis is the unique identifier for the field called in the template, it is recommended to use meaningful lowercase letters, for examplemodel_number/warranty_periodThis name will be used when calling the template, be sure to remember it.
  3. Field type: Choose an appropriate type based on the data characteristics, such as 'Single-line text', 'Number', 'Multi-line text', 'Single selection', 'Multiple selection', or 'Dropdown selection'.If the field content needs to include HTML tags or Markdown syntax, it is recommended to choose 'Multiline Text' and use the corresponding filter on the front end to process it.
  4. Mandatory?: Set according to requirements.
  5. Default valueIf the field has a preset value, it can be filled in here. For fields of selection type, the default value will be listed as an option list, one per line.

After setting up the field, save the model. After that, when you publish or edit the articles under the model, you will see these custom additional fields in the "Other Parameters" section, where you can enter the corresponding data.

Display custom field data in the template.

The AnQi CMS template system uses Django-like syntax and provides flexible tags and filters to handle data. There are mainly two ways to display custom fields:

1. Show data for a single custom field

If you know the name of the custom field's 'reference field' and only need to display specific one or two fields, you can usearchiveDetailThe tag is usually used to retrieve detailed information about the current document, but it also applies to retrieving custom fields.

Assuming we have a custom field with the 'call field' ofproduct_skuWe can display its value in the template like this:

{# 显示当前文档的名为 'product_sku' 的自定义字段值 #}
<div>产品SKU:{% archiveDetail with name="product_sku" %}</div>

{# 如果你想为这个值指定一个变量名,方便后续处理,可以这样做: #}
{% archiveDetail productSkuValue with name="product_sku" %}
<div>产品SKU:{{ productSkuValue }}</div>

{# 你也可以指定其他文档的自定义字段,通过 id 或 token 参数: #}
<div>指定ID文档的产品SKU:{% archiveDetail with name="product_sku" id="10" %}</div>

Please note,nameThe value of the parameter is the name of the 'Call Field' you set in the background.

2. Traverse and display all custom field data

In certain scenarios, you may want to dynamically list all custom fields and their values, such as displaying a 'detailed parameters' list on a product details page. At this point,archiveParamsThe label comes into play. It can retrieve all the additional parameters of the specified document (i.e., custom fields).

archiveParamsThe tag returns an array containing all custom fields (default is sorted), each field includesName(parameter name, that is, the Chinese name displayed in the background) andValue(Parameter value, that is, the data entered) property.

{# 假设我们正在一个文档的详情页,需要显示所有自定义字段 #}
<div>
    <h3>详细参数</h3>
    <ul>
        {% archiveParams params %}
            {% for item in params %}
                {# item.Name 是后台设置的“参数名”(中文),item.Value 是填入的数据 #}
                <li>{{ item.Name }}:{{ item.Value }}</li>
            {% endfor %}
        {% endarchiveParams %}
    </ul>
</div>

{# 如果你想排除某些字段不显示,可以结合 if 标签: #}
<div>
    <h3>部分参数</h3>
    <ul>
        {% archiveParams params %}
            {% for item in params %}
                {% if item.Name != '内部备注' and item.Name != '管理员可见' %}
                    <li>{{ item.Name }}:{{ item.Value }}</li>
                {% endif %}
            {% endfor %}
        {% endarchiveParams %}
    </ul>
</div>

Special consideration when displaying custom fields

  • Rich text or Markdown contentIf your custom field type is multiline text and you expect it to parse HTML or Markdown syntax, you need to use|safeFilter. If the field has the Markdown editor enabled in the background, it can also be配合render=truethe parameters for rendering.

    {# 假设 'detailed_description' 是一个存储富文本或Markdown的自定义字段 #}
    <div>
        <h3>详细描述</h3>
        {# 如果后台Markdown编辑器开启,且希望渲染Markdown #}
        {% archiveDetail detailDesc with name="detailed_description" render=true %}
        {{ detailDesc|safe }}
    
        {# 如果字段是普通HTML,或者Markdown已在后台处理成HTML #}
        {% archiveDetail plainHtmlDesc with name="detailed_description" %}
        {{ plainHtmlDesc|safe }}
    </div>
    
  • Image or file fieldIf your custom field is designed to upload images (for example, a product gallery), the value will usually be a picture URL string, or an array of picture URLs.

    {# 假设 'main_image' 是一个单张图片的自定义字段 #}
    {% archiveDetail mainImage with name="main_image" %}
    {% if mainImage %}<img src="{{ mainImage }}" alt="主图" />{% endif %}
    
    {# 假设 'gallery_images' 是一个多张图片的自定义字段(数组) #}
    {% archiveDetail galleryImages with name="gallery_images" %}
    {% if galleryImages %}
        <div class="product-gallery">
            {% for imgUrl in galleryImages %}
                <img src="{{ imgUrl }}" alt="画廊图片" />
            {% endfor %}
        </div>
    {% endif %}
    

    Here's something to note,Imagesis a special built-in field, which can be used directly as shown above.If your custom field is a single image upload, it will return a string path;If multiple images are uploaded, it may return a string array depending on the field type and backend implementation.

  • Select/Dropdown type fieldThese fields are called directly in the templateitem.ValueIt will display the text value selected by the user. No additional processing is required.

Through these flexible calling methods, Anqi CMS's

Related articles

How to get and display the list of tags and links associated with the article in the template?

In website operation and content management, article tags (Tag) are key tools for improving content organization, user experience, and search engine optimization (SEO) effects.They can not only help users quickly find relevant content of interest, but also provide clearer content theme information for search engines, thus improving the overall performance of the website.AnqiCMS as an efficient content management system provides intuitive template tags, allowing you to easily obtain and display the list of associated tags and links in the template.

2025-11-08

How to display the cover image, thumbnail, or group image of an article on the article detail page?

In Anqi CMS, adding images to the article detail page is an important link to improve the attractiveness of the content and the reading experience, whether it is the cover main image, thumbnail, or multiple group images.Anqi CMS provides a flexible and intuitive way to manage and display these image resources, allowing you to easily achieve diverse visual presentations. ### The Flexible Use of Article Cover Image and Thumbnail In the article detail page, the cover image (Logo) and thumbnail (Thumb) are the most common image elements.They are usually used to represent the main visual content of an article and are widely used on list pages

2025-11-08

How to retrieve and display the publish time, update time, view count, and comment count of an article?

## Mastering AnQi CMS: A Comprehensive Guide to Article Publishing and Interactive Data Display In website operation, clearly displaying the publication and update time of articles, popularity (page views), and reader feedback (number of comments) can not only effectively improve user experience but also enhance the authority and timeliness of the content.AnQiCMS (AnQiCMS) relies on its flexible template tag system to make the acquisition and display of this key information simple and efficient.This article will explain in detail how to implement these functions in Anqi CMS.### One

2025-11-08

How to display the name, link, and hierarchy of the article category on the article detail page?

AnQi CMS is a flexible and efficient content management system that provides great freedom in content display.For a website, the article detail page not only needs to display the content of the article itself, but also the name, link, and even the hierarchical relationship of the category it belongs to, which are all important components for improving user experience, optimizing website structure, and promoting SEO.Clear categorization information can help users quickly understand the positioning of the article, facilitate their further browsing of related content, and also enable search engines to better crawl and understand the structure of the website.Next, we will discuss how to use the Anqi CMS article detail page

2025-11-08

How to retrieve and display the name, description, link, and subordinate category list of a specified category?

In AnQiCMS, effective management and display of website categories are crucial for enhancing user experience and content organization.Whether it is to build a navigation menu, sidebar content, or display a category structure on a specific page, it is a common requirement to flexibly obtain the name, description, link, and list of subcategories under the category.This article will introduce how to use AnQiCMS template tags to easily achieve these functions.

2025-11-08

How to display a category-specific Banner image or thumbnail on the category page?

In website operation, designing unique visual elements for different category pages, such as a prominent banner image or a dedicated thumbnail, is an effective means to enhance user experience, strengthen brand image, and promote content conversion.AnQi CMS provides intuitive and powerful functional support to meet this requirement.How does Anqi CMS support category-specific visual content?

2025-11-08

How to get and display the title, content, link, and thumbnail of a specified single page (such as “About Us”)?

In AnQi CMS, the single-page content of a website such as "About UsThese pages not only need to be displayed under independent URLs, but may also need to extract their titles, summaries, links, or thumbnails in other areas of the website (such as the footer, sidebar, or specific modules on the homepage) for display.Anqi CMS provides simple and powerful template tags, allowing you to easily achieve this requirement in website templates.

2025-11-08

How to obtain and display the website's friend link list in the template?

Managing and displaying friendship links in AnQiCMS is a very practical feature, whether it is to increase the external links of the website, improve SEO effects, or to facilitate users to access partner websites, it can play an important role.AnQiCMS provides a simple and efficient way for us to easily obtain and display these links in the template.### Step 1: Background Management and Configuration of Friend Links Before displaying the friend links on the website front-end, we need to add and manage them in the AnQiCMS background system

2025-11-08