How to retrieve and display the full content of a single document using the `archiveDetail` tag?

In the Auto CMS, displaying the full content of a single document is the foundation of website operation.No matter whether you are publishing a news article, a product detail, or a service introduction, the core lies in how to present the data entered in the backend efficiently and accurately to the users.archiveDetailThe place where labels and their related mechanisms take effect.

UnderstandingarchiveDetail: Get the core of a single document.

When discussing the complete content of a single document, it is first necessary to clarify: when you visit the detail page of a document (for example你的域名/article/123.html),English CMS has already loaded all the data of the current document into a name calledarchiveThe global variable. This means that in the template of the document detail page, you usually can directly call the various information of the document in a quick and concise manner, such as{{archive.字段名}}in the form to quickly and concisely call the various information of the document, such as{{archive.Title}}It will display the document title,{{archive.Content}}it will show the document text.

However,archiveDetailTags provide a more flexible way of control. It allows you to not only get the details of the document on the current page, but also, as needed, explicitly specify through the document ID (id), or URL alias (tokenTo obtain the content of any document. This flexibility is especially useful in scenarios where you need to refer to or compare the content of other documents. Its basic usage is{% archiveDetail 变量名称 with name="字段名称" id="文档ID" %}, or if you just want to output a certain field without defining a variable, it can also be omitted变量名称.

Key field and practical call

To make full use ofarchiveDetailLabel, it is crucial to understand its supported fields.

The first is basic text information. For example, to display the document title, you can use{{archive.Title}}or{% archiveDetail with name="Title" %}. Similarly, the document link (Link) and the description (Description) Keywords (Keywords) and the number of views (Views) and others can be easily obtained in a similar manner. For example, displaying the number of views of the current document on the page:

<p>浏览量:{{archive.Views}} 次</p>

Next are the image resources. The cover image of the document (Logo), thumbnails (Thumb)are common display elements. If the document is configured with multiple cover images(Images),it will return an array, at which point you need to go through(fora loop:

<img src="{{archive.Logo}}" alt="{{archive.Title}}" />

{% if archive.Images %}
<div class="gallery">
    {% for imgUrl in archive.Images %}
    <img src="{{imgUrl}}" alt="图片描述" />
    {% endfor %}
</div>
{% endif %}

the core content fields of the documentContentIs the key to displaying article or product details. It is particularly important to note that since the content usually contains HTML code generated by a rich text editor, in order for the browser to correctly parse and display the style,Make sure to cooperate|safeFilter usageTo prevent HTML from being escaped and displayed as plain text. Moreover, if your content is in Markdown format, you can also go throughrender=true参数让系统自动将其渲染为HTML。

<div class="article-content">
    {{archive.Content|safe}}
    {# 如果内容是Markdown格式,且想强制渲染: #}
    {# {{archive.Content|render=true|safe}} #}
    {# 如果内容是Markdown格式,但想获取原始Markdown文本: #}
    {# {{archive.Content|render=false|safe}} #}
</div>

文档的发布和更新时间(CreatedTimeandUpdatedTime)是Unix时间戳格式,为了便于阅读,您需要使用stampToDateThe function performs formatting. For example, the publish time is formatted as “year-month-day”:

<span>发布时间:{{stampToDate(archive.CreatedTime, "2006-01-02")}}</span>

The flexibility of AnQi CMS also lies in its customizable content model fields. If you add a custom field, such as "author", to a content model in the background,author)or“product model”(modelNumber),You can directly call them through{{archive.author}}or{{archive.modelNumber}}To iterate through all custom fields,archiveParamsTags will be your good helper, it can return all custom fields in array form for easy iteration and display:

{# 直接调用自定义字段 #}
<p>作者:{{archive.author}}</p>

{# 遍历所有自定义字段 #}
{% archiveParams params %}
<ul class="custom-fields">
    {% for item in params %}
    <li><strong>{{item.Name}}:</strong>{{item.Value}}</li>
    {% endfor %}
</ul>
{% endarchiveParams %}

When your website is a multi-site architecture,siteId参数则允许您跨站点调用文档数据,这为多品牌或多语言网站的内容整合提供了便利。

Example of practical application scenarios

场景一:标准文章详情页In a blog or news website, a typical article detail page may contain the title, category links, publish time, tags, view count, and the main content. Here is a concise template snippet showing how to combine this information:

<article class="article-detail">
    <h1 class="article-title">{{archive.Title}}</h1>
    <div class="article-meta">
        <a href="{{archive.Category.Link}}" class="category-link">{{archive.Category.Title}}</a>
        <span class="publish-time">发布于:{{stampToDate(archive.CreatedTime, "2006-01-02")}}</span>
        <span class="views">阅读量:{{archive.Views}} 次</span>
        <div class="tags">
            {% tagList tags with itemId=archive.Id limit="5" %}
            {% for tag in tags %}
            <a href="{{tag.Link}}">{{tag.Title}}</a>
            {% endfor %}
            {% endtagList %}
        </div>
    </div>
    <div class="article-content">
        {{archive.Content|safe}}
    </div>
</article>

Scene two: Product details pageFor e-commerce or product display websites, the product detail page may be more focused on product images, names, detailed specifications, and descriptions. Here, custom fields and image display are combined:

`twig

<div class="product-images">
    <img src="{{archive.Logo}}" alt="{{archive.Title}}" class="main-product-image" />
    {% if archive.Images %}
    <div class="thumbnail-gallery">
        {% for img in archive.Images %}