How to use the `archiveDetail` tag to retrieve and fully display the title, content, and custom fields of a specific document?

Calendar 👁️ 82

In AnQiCMS, displaying the detailed content of a single document is one of the core requirements for website construction.Whether it is an article detail page, a product detail page, or other customized content display, we need a flexible and efficient way to obtain and present the title, content, and custom fields defined according to business requirements.archiveDetailThe label is born for this, it can help you easily achieve this goal.

Get to know in-deptharchiveDetailLabel: Get the core information of a specific document.

archiveDetailThe tag is mainly used to obtain detailed data of a single document. When you need to present all the information of a document completely on a page, it will be your helpful assistant.The strength of this tag lies in its ability not only to obtain the default fields of the document (such as title, content) but also to easily retrieve various fields customized for the document type in the background "content model".

The basic syntax of its use is:{% archiveDetail 变量名称 with name="字段名称" id="文档ID" %}

Among them,变量名称It is optional, if set, you can assign the obtained data to this variable, and then{{变量名称}}use it to refer; if not set, the tag will try to directly output the specified field value.

  • Specify document:Generally speaking,archiveDetailThe document on the document detail page will automatically identify the document on the current page. But if you need to obtainspecific IDdocument information, you can addid="文档ID"parameters, for exampleid="123". In addition, you can also specify the document throughtoken="文档URL别名"parameter.
  • Multi-site support:If your AnQiCMS has deployed multiple sites and you need to retrieve document data across sites, you can usesiteId="站点ID"Parameter.

Get the core information of the document: title and content

To display the document title and content, you just need to specifynamethe corresponding field name in the parameters.

  1. To get the document title (Title):The document title is the core identifier of the content. Usename="Title"to get it.

    {# 获取当前页面文档的标题 #}
    <h1>{% archiveDetail with name="Title" %}</h1>
    
    {# 获取ID为1的文档标题,并赋值给archiveTitle变量 #}
    {% archiveDetail archiveTitle with name="Title" id="1" %}
    <p>指定文档标题:{{ archiveTitle }}</p>
    
  2. Retrieve document content (Content):Document content usually contains rich HTML structures, including text, images, links, etc. When retrieving, it is important to pay attention to a crucial filter:|safe.

    {# 获取当前页面文档的内容,并使用|safe过滤器防止HTML转义 #}
    <div class="article-content">
        {% archiveDetail articleContent with name="Content" %}
        {{ articleContent|safe }}
    </div>
    
    {# 如果您的内容包含Markdown语法,可以使用render=true进行转换 #}
    <div class="article-content">
        {% archiveDetail articleContent with name="Content" render=true %}
        {{ articleContent|safe }}
    </div>
    
    {# 如果您使用了图片懒加载插件,可以指定lazy="data-src"来适配 #}
    <div class="article-content">
        {% archiveDetail articleContent with name="Content" lazy="data-src" %}
        {{ articleContent|safe }}
    </div>
    

    Special reminder: ContentFields typically store rich text content with HTML tags. In order for the browser to correctly parse and display these HTML structures, youit mustuse at output time|safefor example, a filter (such as{{ articleContent|safe }}Otherwise, HTML tags will be displayed as plain text on the page, affecting the reading experience.

Deeply customize fields: flexibly display personalized content.

AnQiCMS is a powerful "content model" feature that allows you to add various custom fields for different types of documents to meet specific business needs, such as product prices, article authors, video durations, and so on.archiveDetailThese labels fully support retrieving these custom fields.

  1. Get a specific custom field:If you know the name of the 'invoked field' custom field (defined in the backend content model), you can go through it directlyname="自定义字段名"Get its value.

    Suppose you have defined a named field in the content modelauthor: custom field

    {# 获取当前文档的作者信息 #}
    <p>作者:{% archiveDetail with name="author" %}</p>
    
    {# 获取ID为10的文档的产品价格字段 #}
    <p>产品价格:{% archiveDetail with name="price" id="10" %}</p>
    
  2. Loop to display all custom fields (archiveParams):Sometimes, you may want to iterate over all custom fields in a document, especially in scenarios like product parameter lists. At this time, you can usearchiveParamsTag to get all custom parameters of the document, then throughforDisplay in a loop.

    <div class="custom-params">
        <h3>更多参数:</h3>
        {% archiveParams params %}
        {% for item in params %}
        <p>
            <span>{{ item.Name }}:</span>
            <span>{{ item.Value }}</span>
        </p>
        {% endfor %}
        {% endarchiveParams %}
    </div>
    

    archiveParamsTag will return an array (or map, depending onsortedparameters).item.Nameis the display name of the custom field,item.ValueIt is the corresponding value.

Comprehensive example: Build a complete document detail page.

Integrate the above elements, a typical document detail page template snippet may look like this:

``twig <!DOCTYPE html>

<meta charset="UTF-8">
<title>{% archiveDetail with name="Title" siteName=true %}</title>
<meta name="description" content="{% archiveDetail with name="Description" %}">
<meta name="keywords" content="{% archiveDetail with name="Keywords" %}">
<link rel="stylesheet" href="{% system with name="TemplateUrl" %}/css/style.css">

<header>
    <!-- 导航、Logo等页面头部元素 -->
</header>

<main class="container">
    <article class="document-detail">
        <h1 class="document-title">{% archiveDetail with name="Title" %}</h1>

        <div class="document-meta">
            <span>分类:<a href="{% categoryDetail with name='Link' %}">{% categoryDetail with name='Title' %}</a></span>
            <span>发布日期:{% archiveDetail with name="CreatedTime" format="2006-01-02" %}</span>
            <span>浏览量:{% archiveDetail with name="Views" %}</span>
            {% archiveDetail author with name="author" %}{# 假设有一个自定义字段叫 author #}
            {% if author %}<span class="document-author">作者:{{ author }}</span>{% endif %}
        </div>

        <div class="document-description">
            <p>{% archiveDetail with name="Description" %}</p>
        </div>

        <div class="document-content">
            {% archiveDetail documentContent with name

Related articles

How to accurately control the display quantity, sorting, and filtering conditions of the `archiveList` tag?

In Anqi CMS, the `archiveList` tag is a core tool for dynamically calling and displaying document lists.Whether it is a blog article, product showcase, or news update, this tag can help you flexibly control the display quantity, sorting method, and various filtering conditions according to your specific needs.A deep understanding of its parameters will enable you to build a highly customized and powerful content display page.

2025-11-08

How to customize independent display templates for specific content on the AnQiCMS website (such as documents, categories, single pages)?

In website operation, we often encounter scenarios where we need to give specific content a unique appearance.It may be a "About Us" page carrying important information, needing a unique layout; it may also be a series of product details, hoping to show different parameter comparisons; or even a content category, looking forward to presenting the list in a more attractive way.

2025-11-08

How does AnQiCMS's adaptive, code adaptation, and PC+Mobile independent mode affect the display effect of the website on different devices?

In today's multi-screen interconnected era, whether a website can display smoothly and efficiently on different devices is directly related to user experience and brand image.AnQiCMS is a rich-featured enterprise-level content management system that fully understands this, providing users with three flexible website display modes to meet the diverse needs of device access: adaptive, code adaptation, and PC+Mobile independent mode.Understanding the working principles and their impact on the display effects of websites is crucial for operators.

2025-11-08

How to ensure UTF-8 encoding when creating AnQiCMS templates to avoid garbled front-end pages?

When using AnQiCMS to build a website, ensure that the front-end pages display normally and avoid annoying garbled characters, which is an important detail that every operator needs to pay attention to.Where, the character encoding of the template file is a key point.If the encoding setting of the template file is incorrect, even if the content of the website itself is not a problem, the page that ultimately appears to the user may be a bunch of unrecognizable characters.

2025-11-08

How do the `prevArchive` and `nextArchive` tags display the link and title of the previous/next document on the document detail page?

When we browse content on the website built with AnQiCMS, carefully crafted documents bring value to readers.It is particularly important to provide 'Previous' and 'Next' navigation links at the end of each article to make the reader's reading experience more smooth and encourage them to explore more relevant content.This can effectively guide users to deeply browse within the website, increase page visits and user stickiness, and is also very beneficial for the internal link structure and SEO optimization of the website.

2025-11-08

How to use the `categoryList` tag to build a multi-level category navigation or display category lists in the content area?

In Anqi CMS, properly organizing website content categories is an important aspect for improving user experience and website maintainability.Whether it is to build a clear multi-level navigation menu, help users quickly locate information, or skillfully display different categories of content in the page content area, the `categoryList` tag is the core tool for realizing these functions. ### Core Tag: `categoryList` Description The `categoryList` tag is used specifically in the Anqi CMS template engine to retrieve the website category list.

2025-11-08

How to retrieve and display the name, description, Banner image, and thumbnail of a specific category using the `categoryDetail` tag?

In AnQiCMS template creation, we often need to retrieve and display detailed information about specific categories, such as the name, description, and even preset Banner images and thumbnails.`categoryDetail` tag is born for this, it helps us easily extract this data from the database and flexibly display it on the website front end.

2025-11-08

How to effectively manage and display single-page content on a website using `pageList` and `pageDetail` tags?

In website operation, single-page content plays an indispensable role, it usually carries important information such as "About Us", "Contact Us", "Terms of Service", "Privacy Policy", etc., which needs to be clearly displayed and also requires convenient management.AnQiCMS provides the powerful template tags `pageList` and `pageDetail`, which help us efficiently manage and display these single-page content.

2025-11-08