On the document detail page, how to call and display the custom model field content of the article?

Calendar 👁️ 72

The flexible content model of AnQiCMS is a powerful tool that allows us to add custom fields for different types of content (such as articles, products, events, etc.) according to the actual needs of the website.This means that our content is no longer limited to fixed titles, summaries, and content, but can carry more diverse and structured information.How do we call and display the content of these custom model fields on the document detail page?

Next, let's explore the various flexible ways provided by Anqi CMS together.

Understand the creation and role of custom model fields.

Before delving into template calls, it is necessary to briefly review the process of creating custom model fields. In the Anqi CMS backend, you can accessContent ManagementContent modelCome manage and create content models. Whether it is the default system models such as "Article Model" and "Product Model", or the models you add yourself, you can add custom fields to them.

When adding fields, there are several key points to note:

  1. Parameter name (display name): This is the field name you see when editing documents in the background, such as "Article Author", "Product Model".
  2. Field call (English name)This is used when calling the field content in the templateUnique identifierIt must be alphabetic. For example, if you set the call field for "Article Author" toauthorThen you will use in the templateauthorGet its value.
  3. Field type: AnQi CMS supports various field types such as single-line text, numbers, multi-line text, single choice, multiple choice, and drop-down selection, etc.Different field types may require different handling when displayed on the front end.

When you are editing a document in the background, if the category associated with the document is linked to a content model, then all the custom fields defined under this content model will be displayed in the "Other Parameters" section for you to fill in the corresponding content.Ensure that these fields are filled in and saved, as this is a prerequisite for the front-end to function successfully.

Call the custom model field content in the document detail page

Once the content of the custom model field is entered in the background, we can then access the corresponding template file on the document detail page (usuallytemplate/您的模板目录/模型表名/detail.htmlordetail-{文档ID}.html),Through the following ways to call and display them.

1. The most direct way: througharchiveObject property calling

This is the most commonly used and simplest way, suitable for most custom fields. In the template of the document detail page, Anqi CMS will automatically wrap all the data of the current document in a namedarchiveIn the object. This object includes the default fields of the document (such asTitle/Content/Description), also includes all the custom model fields you have defined.

You only need to use dot syntax (.It can directly access the content of custom fields. For example, if you have a field namedauthorof the called field:

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

If your custom field type is a rich text editor (multi-line text and allows HTML), to ensure that the HTML content can be correctly parsed and displayed in style, you need to use|safeFilter:

<div class="product-introduction">{{ archive.introduction|safe }}</div>

This method is simple and clear, highly recommended as the first choice.

2. UsearchiveDetailLabel calls accurately

archiveDetailTags are specifically used to retrieve document details, they can not only retrieve built-in document fields but also be used to retrieve content of custom model fields. This method is used in some cases where finer control is needed or only specific field values are needed without introducing the entirearchiveIn the case of an object it will be more useful.

Suppose you have a custom call field.product_dimensions(Product size):

<p>产品尺寸:{% archiveDetail with name="product_dimensions" %}</p>

You can also assign the obtained value to a variable and then process it:

{% archiveDetail dimensions_value with name="product_dimensions" %}
<p>产品的具体尺寸是:{{ dimensions_value }}</p>

For some special fields, such as custom album fields (for examplegallery_images), it stores a list of image URLs. You can obtain thearchiveDetailtags and then loop through them to display:

{% archiveDetail gallery with name="gallery_images" %}
<div class="product-gallery">
    {% for img_url in gallery %}
        <img src="{{ img_url }}" alt="产品图" />
    {% endfor %}
</div>

3. Use.archiveParamsLabel traversal or access as needed

If you want to dynamically iterate through all custom fields and their corresponding names and values in a template, or need to directly access a custom field in the form of a key-value pair,archiveParamsTags will be your helpful assistant.

By default,archiveParamsTags will return a sorted array object, each element containingNameand (parameter name)Value(parameter value). You can loop through and display all custom fields like this:

<div class="custom-parameters">
    {% archiveParams params %}
    {% for item in params %}
        <p>{{ item.Name }}:{{ item.Value }}</p>
    {% endfor %}
    {% endarchiveParams %}
</div>

If your custom field is rich text, don't forget to{{ item.Value }}added afterwards|safefilter.

In addition, you can also setsorted=falseto get an unordered onemapAn object (similar to a dictionary), so you can directly retrieve the value of a custom field by its English name (i.e., 'call field') without looping:

{% archiveParams custom_fields with sorted=false %}
    <p>作者邮箱:{{ custom_fields.author_email.Value }}</p>
    <p>是否推荐:{{ custom_fields.is_featured.Value }}</p>
{% endarchiveParams %}

This method is very convenient when you know which specific custom field you want to retrieve and need itsValueproperty (orNameproperty).

Summary and **practice**

Anqi CMS provides a flexible content model and a powerful template tag system, making the invocation of custom model fields intuitive and efficient. In practice:

  • For most scenarios, go directly through{{ archive.your_custom_field_name }}Property calling is the simplest choice.
  • If the custom field is rich text content, be sure to use|safeFilter, for example{{ archive.rich_text_field|safe }}To prevent HTML from being escaped and not displayed correctly.
  • archiveDetailTags are suitable for situations where additional processing or assignment needs to be done for individual fields.
  • archiveParamsThe label is very suitable for scenarios where it is necessary to dynamically display all custom fields, or quickly access specific values in the form of key-value pairs.

Related articles

How to implement personalized front-end display for different types of content (articles, products, single pages) in AnQi CMS?

In AnQi CMS, achieving personalized front-end display of different types of content (such as articles, products, and single pages) is one of its core advantages, and it is also a key factor for content operators to achieve brand differentiation and improve user experience.This is mainly due to the flexible content model design and powerful template customization capabilities of Anqi CMS. ### Flexible Content Model: The Foundation of Personalized Display The core of Anqi CMS lies in its "flexible content model".This means you are not limited to fixed "article" or "product" types, but can customize various content models according to your actual business needs. For example

2025-11-08

How to customize the display fields of an Anqi CMS content model to meet specific business requirements?

In website operation, the diversity and personalization of content are the key to attracting users and improving efficiency.AnQiCMS (AnQiCMS) understands this and therefore provides powerful content model customization features, allowing us to flexibly adjust the display fields of content according to specific business needs.This article will take you in-depth to understand how to use this powerful feature to create a content management experience that is more tailored to your business scenario.Why do we need to customize content model fields?You may encounter such a situation: The default "article" or "product" model is general, but in actual operation

2025-11-08

How to configure custom parameters in the background of AnQiCMS and flexibly call and display them in the front-end template?

In website operation, we often encounter the need to add personalized information outside of standard fields for content or the global website.This information may be a description of the unique features of a website, product parameters, specific attributes of an article, or even multi-channel contact information.AnQiCMS (AnQiCMS) fully understands the importance of this flexibility, and therefore provides powerful custom parameter configuration features, allowing you to easily define the required data in the background and flexibly call and display it in the front-end template.

2025-11-08

How to automatically convert newline characters in multi-line text in AnQiCMS templates to the HTML `<br/>` tag?

In AnQiCMS template, how to make the newline character of multiline text automatically display as the HTML `<br/>` tag?In website content operation, we often encounter situations where we need to display multi-line text, such as article summaries, product descriptions, or user comments.This text content is usually created by pressing the Enter key when editing in the background.However, when this text containing newline characters (usually `\n`) is directly output to an HTML page, the browser will not parse it as a visual line break.On the contrary, HTML

2025-11-08

How to set up independent display template files for specific articles or categories?

In the daily operation of websites, we often encounter such situations: some articles are in-depth reports, some are promotional pages for events, and some are corporate profiles or product details.They each have unique display requirements, and if they all follow the website's general template, it may seem monotonous and fail to fully exert the appeal of the content.AnQi CMS is an efficient and flexible content management system that fully considers this personalized demand, allowing us to set independent display template files for specific articles, categories, even single pages, making the content display more tailored and impactful.

2025-11-08

How does Anqi CMS template support adaptive, code adaptation, and independent display mode on PC and mobile?

How to ensure that the website can provide a high-quality user experience on different devices is a challenge that cannot be ignored in today's content marketing and website operations.AnQiCMS (AnQiCMS) knows this, therefore it provides flexible and diverse adaptation modes in template design and content display, allowing users to easily deal with various terminal access scenarios according to their own needs.

2025-11-08

What are the common variable naming and tag syntax rules (such as `{{variable}}` and `{% tag %}`) when making AnQiCMS templates?

To create templates in AnQiCMS and master its variable naming and tag syntax rules is the core.The system is developed based on the Go language, the template engine borrows the syntax style of Django and Blade, making content output and logical control very intuitive.When you are doing template development, you will mainly encounter two basic syntax structures, each of which has different responsibilities.### Core grammar structure: variable output and logical control First are double curly braces `{{ variable }}`, which have a very direct function

2025-11-08

How to efficiently organize and reference common page header, footer, and other code snippets in the front-end page template?

Manage front-end page code in AnQi CMS, especially the header, footer, and other code snippets that need to be repeated on multiple pages, which is a key to improving development efficiency and website maintainability.AnQi CMS provides a powerful and flexible template engine, allowing us to organize and reference these common codes in an elegant way. ### The Importance of Template Reusability Imagine if your website has dozens, even hundreds of pages, each of which independently contains the complete header, navigation, and footer code. When the website's logo needs to be replaced, or the footer copyright information needs to be updated

2025-11-08