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