How to get the custom model field content of the `archiveDetail` tag?

Calendar 👁️ 51

In the powerful and flexible AnQiCMS content management system, the content model plays a core role, allowing us to build various personalized content structures according to business needs.Whether it is an article, product, event, or other custom information, we can define unique fields for it.How can one elegantly present these rich custom field contents on the front-end page, which has become the key to template development.archiveDetailThe power of tags, especially how they help us easily obtain the custom model fields of documents.

The flexible cornerstone of AnQiCMS: content model and custom fields

Let's briefly review the content model of AnQiCMS.In the AnQiCMS backend, we can create or edit different content types through the 'Content Management' module under the 'Content Model' feature.For example, an "article" model may include basic fields such as "title", "content", "publish time", but business requirements may also require recording fields such as "article author", "article source", "editor in charge", etc.For example, a "product" model may also require "product model

These 'article author', 'product model', 'brand' and so on are the custom fields we define for a specific content model.AnQiCMS provides various field types such as single-line text, multi-line text, numbers, single selection, multiple selection, and images (group images), greatly enriching the content presentation.After defining these fields, when we publish the content of the corresponding model, we can fill in these additional information.

Deep understandingarchiveDetailLabel: The universal key to document details

In AnQiCMS template design,archiveDetailThe tag is used to obtain all detailed information of a single document on the document detail page.It is like a universal key that can easily extract document data from the current page or a specified ID.archiveDetailIts real power lies in its ability to seamlessly integrate with our custom content model fields.

When we need to display detailed information of a document on the document detail page, we usually use this tag. Its basic usage is:{% archiveDetail 变量名称 with name="字段名称" %}.If a variable name is not specified, it will directly output the field content; if a variable name is specified, the obtained data can be stored in the variable for subsequent more complex processing.

Unlock custom model field:archiveDetailAdvanced usage of

Now, let's focus on the core issue: how toarchiveDetailget the custom model field content through tags.

AnQiCMS provides a very intuitive way for this. Whether your custom field is simple text, numbers, or complex arrays (such as group images) or multiple choices,archiveDetailCan all胜任.

  1. Get a single text or numeric custom field:Assuming we add a field named "author" (the calling field is namedauthor)” and a field named “Reading Time (field calledreadDuration)” custom field. We can easily access them in the article detail page template:

    <p>作者:{% archiveDetail with name="author" %}</p>
    <p>预计阅读时长:{% archiveDetail with name="readDuration" %} 分钟</p>
    

    The key point is herename="author"andname="readDuration".nameThe value of the parameter must match the name of the 'called field' you entered when defining custom fields on the AnQiCMS backend.

  2. Retrieve complex custom fields: take a group chart as an example:If our custom field is a relatively complex type, such as adding a named 'Product image set' field for the 'Product' modelproductImagesThe group field that indicates this is usually an array of image URLs. To display these images in a loop on the front end, we need to convertarchiveDetailAssign the obtained data to a variable, thenforloop through it.

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

    In this example,{% archiveDetail productImages with name="productImages" %}Assign the obtained image URL array toproductImagesthe variable. Then, we can use{% for imageUrl in productImages %}Loop through and display each image

Practical application: Custom information display on product detail page

Let's combine a real-world scenario to build a product detail page fragment, which includes built-in fields and multiple custom fields:

Assuming our 'Product' model in addition to built-in fields also customizes the following fields:

  • Brand:Field invocationbrand(Single-line text)
  • Model:Field invocationmodel(Single-line text)
  • Product features:Field invocationfeatures(Multiline text, may contain HTML format)
  • Product image set:Field invocationgallery(Group photo)

The product detail page template code snippet may be as follows:

<div class="product-detail-container">
    <h1>{% archiveDetail with name="Title" %}</h1> {# 内置标题字段 #}

    <div class="product-info">
        <p>品牌:{% archiveDetail with name="brand" %}</p> {# 自定义品牌字段 #}
        <p>型号:{% archiveDetail with name="model" %}</p> {# 自定义型号字段 #}
        <p>浏览量:{% archiveDetail with name="Views" %}</p> {# 内置浏览量字段 #}
        <p>发布日期:{{ stampToDate(archive.CreatedTime, "2006年01月02日") }}</p> {# 内置发布时间字段 #}
    </div>

    <div class="product-gallery">
        {% archiveDetail productGalleryImages with name="gallery" %} {# 获取自定义组图字段 #}
        {% if productGalleryImages %}
            {% for image in productGalleryImages %}
                <img src="{{ image }}" alt="{% archiveDetail with name="Title" %} - 产品图" />
            {% endfor %}
        {% else %}
            <img src="{% archiveDetail with name="Logo" %}" alt="{% archiveDetail with name="Title" %} - 主图" /> {# 如果没有组图,显示内置Logo #}
        {% endif %}
    </div>

    <div class="product-description">
        <h2>产品概述</h2>
        {% archiveDetail productDescription with name="Description" %} {# 内置描述字段 #}
        <p>{{ productDescription }}</p>
    </div>

    <div class="product-features">
        <h2>产品特点</h2>
        {% archiveDetail productFeatures with name="features" %} {# 获取自定义产品特点字段 #}
        <div class="features-content">{{ productFeatures|safe }}</div> {# 假设产品特点可能包含HTML,使用|safe过滤器 #}
    </div>

    <div class="product-full-content">
        <h2>详细内容</h2>
        {% archiveDetail articleContent with name="Content" %} {# 内置内容字段 #}
        <div class="full-content">{{ articleContent|safe }}</div> {# 内容通常包含HTML,需要|safe #}
    </div>
</div>

In this example, we clearly see thatarchiveDetailHow to flexibly obtain built-in information of documents, as well as the 'brand', 'model', 'product image set', and 'product features' fields we have customized for the 'product' model. For fields that may contain HTML content (such as 'product features' or main content), we have used|safeFilter, ensure that HTML tags are parsed correctly and not displayed as plain text.

Summary

archiveDetailTags are an indispensable tool in the development of AnQiCMS templates.It not only helps us display the basic information of the document, but more importantly, it provides a simple and powerful mechanism to access and utilize various fields defined in the custom content model.nameParameters and flexible variable assignment, we can perfectly map the personalized content structure built in the background to the front-end page, thereby providing users with rich and customized content experience.Mastering this usage will undoubtedly greatly enhance your efficiency in content operation and website development on AnQiCMS.


Frequently Asked Questions (FAQ)

  1. Q: Why do I use{% archiveDetail with name="my_custom_field" %}but can't display the content? A:This situation usually has several reasons: first, please checknameDoes the value of the parameter match the name of the 'call field' you defined in the AnQiCMS backend, including case sensitivity.Next, confirm that the document you are viewing has indeed filled in the content of the custom field.If the field content is empty, the front-end will not display any information naturally.my_custom_fieldcustom field.

  2. Q: Why is my custom field displayed as HTML source code instead of formatted content, being a rich text editor type? A:This is because the AnQiCMS template engine defaults to escaping all output content to prevent XSS attacks. If your custom field content is already HTML code (for example, from a rich text editor), you need to use|safeThe filter tells the template engine that this content is safe and does not need to be escaped. For example:{% archiveDetail customRichText with name="myRichTextField" %}{{ customRichText|safe }}.

  3. Q: BesidesarchiveDetailAre there other ways to retrieve the custom field content of the document? A:Yes, except when used on the document detail pagearchiveDetailTags get the custom fields of the current document, and you can also use them in the document list loop (for example, usingarchiveListWhen a label is used), it can be accessed by referring to the custom properties of the loop variable. For example, in aarchiveListofforloop, ifitemit is the current document object, and you have a namedauthorThe custom field can be accessed directly{{ item.Author }}Note that the field name is usually capitalized first

Related articles

How does the `archiveDetail` tag in AnQiCMS control the Markdown rendering or lazy loading of document content?

As an experienced website operations expert, I know that in the increasingly fierce online environment, efficient content management and elegant presentation are crucial for the success of a website.AnQiCMS is a powerful and flexible content management system that provides us with great convenience with its template tag system.Today, let's delve deeply into a seemingly simple yet powerful tool: the `archiveDetail` tag of AnQiCMS, especially its mysteries in controlling the Markdown rendering and lazy loading of document content.

2025-11-06

How to get the SEO title, keywords, and description of the current document and use it in the page Meta tags?

As an expert well-versed in website operations, I know the importance of SEO titles, keywords, and descriptions (usually referred to as TDK, Title, Description, Keywords) for a website to perform well in search engines.They are the information that users see first on the search results page, directly affecting the click-through rate, and are also a key signal for search engines to understand the content of the page.

2025-11-06

How to combine `archiveList` with `pagination` tag to implement pagination navigation for document list?

As an experienced website operation expert, I am well aware of the importance of an efficient content management system (CMS) for website operation. AnQiCMS, with its high concurrency features in Go language and flexible template mechanism, has provided us with great convenience.Among many features, how to effectively display a large number of documents and provide friendly pagination navigation is crucial for improving user experience and content accessibility.Today, let's delve into how the `archiveList` tag cleverly combines with the `pagination` tag

2025-11-06

How to display the Flag attribute of the document in the `archiveList` loop, for example, 'Recommended' or 'Bold'?

As an experienced website operations expert, I am happy to deeply analyze how to flexibly use the `archiveList` loop in AnQiCMS to display the Flag attribute of documents, such as "recommended" or "bold".The core of content operation lies in how to effectively distinguish and highlight key content, and the Flag attribute is a powerful and easy-to-use feature provided by AnQiCMS for this purpose.--- ### Light up your content

2025-11-06

How to create a document filtering interface with the `archiveFilters` tag?

AnQi CMS is an efficient and customizable enterprise-level content management system, dedicated to providing powerful and flexible content management tools for website operators.In daily operations, we often need to provide users with a diverse range of content filtering functions to help them quickly find the information they are interested in.At this time, the `archiveFilters` tag provided by AnQi CMS can fully display its capabilities, allowing us to easily build a multi-condition document filtering interface, greatly enhancing the user's content discovery experience.### Understand `archiveFilters`

2025-11-06

How to iterate over and display each filter parameter's optional values and their corresponding links for the `archiveFilters` tag?

Good, as an experienced website operation expert, I am happy to delve into the exquisite features of the `archiveFilters` tag in AnQi CMS and guide you on how to flexibly apply it in practice to build a beautiful and practical content filtering function. --- ## Deep Analysis of AnqiCMS: `archiveFilters` tag, building a dynamic content filtering tool In the world of content management, how to help users quickly find the information they need is the key to improving website experience and conversion rates.Deeply understands this path of AnQi CMS

2025-11-06

How to determine if a document belongs to the current page category in the `archiveList` loop?

As an experienced website operations expert, I know that the flexible use of templates in content management systems is the key to enhancing the dynamism of websites and user experience.AnQiCMS (AnQiCMS) provides us with powerful content display capabilities with its efficient architecture based on the Go language and Django-style template syntax.Today, let's delve into a very practical template technique: how to cleverly determine whether the current document belongs to the current page category within the `archiveList` loop.

2025-11-06

How to get the documents of a specified user, or only display the documents under the current category without including subcategories?

As an experienced website operations expert, I am well aware of the importance of a flexible and efficient content management system for website operations.AnQiCMS, with its lightweight, high-performance, and highly customizable features, has won the favor of many small and medium-sized enterprises and content operators.In the daily content operation, we often need to manage and display the website content in a refined manner, among which, how to accurately obtain the documents of a specific author, or only display the content under the current category while excluding the subcategories, is the key to improving user experience and optimizing the content structure.Today, let's delve deeper

2025-11-06