How to call document detail data (archiveDetail) in AnQiCMS template?

Calendar 👁️ 77

As an experienced AnQi CMS website operation personnel, I know that content is the core of the website, and how to efficiently and accurately display these contents is the focus of our daily work. Today, we will delve into a crucial tag in the AnQiCMS template -archiveDetailIt can help us flexibly call and display the detailed data of the document.

UnderstandingarchiveDetailThe core role of tags

In AnQiCMS, whether it is articles, products, or content of other custom models, we all call it 'documents' (archive).archiveDetailThe core function of the label is to retrieve and display the detailed information of a single document in the template.It allows us to accurately specify which fields of which documents to retrieve, thus meeting various content display needs.

In most cases, when we visit a document detail page, AnQiCMS automatically identifies the document ID of the current page, at this time we do not need to specify the ID additionally,archiveDetailIt can directly obtain the data of the current document. However, in some scenarios where specific document data needs to be displayed (such as recommended articles in the sidebar or related articles on the product page), we need to specify the document explicitly through parameters.

archiveDetailBasic usage and parameter parsing

archiveDetailThe usage of tags is very intuitive, its basic syntax structure is:

{% archiveDetail [变量名称] with name="字段名称" [id="文档ID"] [token="文档URL别名"] [siteId="站点ID"] %}

Let's delve into these parameters in detail:

  • name="字段名称"This is the most critical parameter, used to specify the specific field you want to retrieve from the document. For example,name="Title"It will retrieve the document title,name="Content"It will retrieve the content of the document.
  • id="文档ID"If you want to get a document that is not currently displayed on the page, but a specific ID document in the website, you can specify this parameter. For example,id="10"Will retrieve the document data for ID 10.
  • token="文档URL别名": withidSimilarly, you can also specify the document by its URL alias (usually the unique identifier in the pseudo-static link).
  • siteId="站点ID"In a multi-site management environment, if you need to call document data from other sites, you can specify the site ID through this parameter.In most cases, this parameter does not need to be filled in, the system will default to fetching data from the current site.
  • [变量名称]This is an optional parameter. If you want to assign the obtained document data to a variable for more complex processing in the template (such as conditional judgment, loop, or combination display of multiple fields), you can define a variable name here.If the variable name is not specified, the label will directly output itsnameThe value specified by the parameter.

Example of calling common fields

archiveDetailTags can access various built-in fields of the document. Here are some of the fields most commonly used by our operation staff and their calling methods:

Document title (Title)

This is the core of any content page. Throughname="Title"you can easily display the document title.

{# 直接输出当前文档标题 #}
<h1>{% archiveDetail with name="Title" %}</h1>

{# 获取ID为5的文档标题并赋值给变量 #}
{% archiveDetail myDocTitle with name="Title" id="5" %}
<p>相关文章:{{ myDocTitle }}</p>

Document content (Content)

The document content is the main body of the page,ContentThe field also supports two important properties:

  • lazy="data-src"If you have used a lazy loading plugin for images, you can use this attribute to<img>label'ssrcattribute is replaced withdata-srcetc., to optimize page loading performance.
  • render=true|falseWhen the content includes Markdown format, set it torender=trueCan automatically convert it to HTML. If your content is already pure HTML or does not need to be converted, it can be set torender=false.
{# 直接输出当前文档内容,并支持图片懒加载和Markdown渲染 #}
<div class="article-content">
    {% archiveDetail with name="Content" lazy="data-src" render=true %}
</div>

{# 获取特定文档内容并赋值,不进行Markdown渲染 #}
{% archiveDetail articleBody with name="Content" id="12" render=false %}
<div class="excerpt">{{ articleBody|safe }}</div>

Please note that when the output content contains HTML tags, it is usually necessary to add|safea filter to prevent HTML from being escaped and unable to display normally.

Document link (Link)

Get the URL link of the document, commonly used to build navigation or related recommendations.

<a href="{% archiveDetail with name="Link" %}">阅读更多</a>

Document creation time (CreatedTime) With update time (UpdatedTime)

These fields return timestamps, which need to be coordinated withformatThe parameter is formatted for display. The AnQiCMS time formatting follows the Go language rules, for example"2006-01-02"represents year, month, and day.

<p>发布时间:{% archiveDetail with name="CreatedTime" format="2006年01月02日 15:04" %}</p>
<p>最近更新:{% archiveDetail with name="UpdatedTime" format="2006-01-02" %}</p>

Document cover image (Logo/Thumb) and multiple images (Images)

  • Logo: Typically used to get the main image or large image of the document.
  • Thumb: Used to get the thumbnail of the document, suitable for list display.
  • ImagesIf the document contains a set of images (such as a product detail carousel), this field will return an array of image URLs.
{# 显示文档主图 #}
<img src="{% archiveDetail with name="Logo" %}" alt="{% archiveDetail with name="Title" %}">

{# 循环显示一组图片 #}
{% archiveDetail galleryImages with name="Images" %}
{% if galleryImages %}
    <div class="product-carousel">
        {% for imgUrl in galleryImages %}
            <img src="{{ imgUrl }}" alt="图片">
        {% endfor %}
    </div>
{% endif %}

Document classification (Category)

Get the category information of the document. This field will return an object containing category ID, title, link, and other properties.

{% archiveDetail docCategory with name="Category" %}
<p>分类:<a href="{{ docCategory.Link }}">{{ docCategory.Title }}</a></p>

Custom field of the document

AnQiCMS content model allows us to add custom fields, such as "author", "source", or "product parameters". These custom fields can be directly accessed via the "call field" names defined in the backend asnameParameter to obtain.

Assuming you have a custom field, you can call the field nameauthor:

<p>作者:{% archiveDetail with name="author" %}</p>

If you want to display all custom fields, especially those that are not fixed, you can usearchiveParamstags to loop through.

{# 在文档详情页,循环显示所有自定义参数 #}
{% archiveParams customFields %}
    {% for param in customFields %}
        <p>{{ param.Name }}:{{ param.Value }}</p>
    {% endfor %}
{% endarchiveParams %}

Application based on actual scenarios

Assuming we need to display a product detail page, in addition to showing the detailed information of the product itself, we also recommend a related 'User Manual' article in the sidebar.

{# 产品名称 #}
<h1>{% archiveDetail with name="Title" %}</h1>

{# 产品描述 #}
<div class="product-description">
    {% archiveDetail with name="Description" %}
</div>

{# 产品主图 #}
<div class="product-image">
    <img src="{% archiveDetail with name="Logo" %}" alt="{% archiveDetail with name="Title" %}">
</div>

{# 产品参数(假设自定义字段名为 "parameters") #}
<div class="product-specs">
    <h2>产品参数</h2>
    {% archiveDetail productParams with name="parameters" %}
    {# 假设parameters字段存储的是JSON字符串或简单文本 #}
    <p>{{ productParams }}</p>
</div>

{# 侧边栏推荐文章:假设我们知道“使用教程”文章的ID是20 #}
<div class="sidebar">
    <h3>相关教程</h3>
    {% archiveDetail tutorialArticle with name="Title" id="20" %}
    {% archiveDetail tutorialLink with name="Link" id="20" %}
    <a href="{{ tutorialLink }}">{{ tutorialArticle }}</a>
</div>

ByarchiveDetailThe flexible use of tags allows us to accurately control the content displayed on each page, achieving a highly customized frontend display effect, thus better attracting and retaining users.Mastering this tag is a key step for efficient content operation on AnQiCMS.


Frequently Asked Questions (FAQ)

Ask: How can I get all information of the current document in the template, not just a single field?

Answer:archiveDetailTags are mainly used to obtain the value of a single field. If you want to obtain the entire data object of the current document, and assign it to a variable so that you can use its multiple properties more flexibly in the template (for example{{archive.Title}}/{{archive.Link}}As a matter of fact, you usually do not need to use it explicitlyarchiveDetailtag to get all. In the context of the document detail page, the system usually automatically exposes the complete data of the current document as a namedarchive(or similar name, depending on the template structure) global variable. You can access its properties directly through{{ archive.字段名 }}. If you indeed need to access througharchiveDetailTo get the entire object, this usually requires tonameLeave the parameter empty and assign the entire data to a variable, but this usage is less direct for obtaining all fields and is more commonly used as an internal mechanism of the system.

Ask: My document content is in Markdown format, but the front-end displays the raw Markdown text. How can I render it correctly into HTML?

Answer: When you usearchiveDetailTag callname="Content"you can addrender=truethe parameter to indicate that the system should convert Markdown content to HTML. For example:{% archiveDetail with name="Content" render=true %}. In order to ensure that the converted HTML can be correctly parsed by the browser rather than displayed as plain text, you usually need to add to the output|safeFilter, for example{{ archiveContent|safe }}.

Ask: I have created a custom content model and added custom fields. How can I call the values of these custom fields in the template?

Answer: Calling custom fields is very simple. When you usearchiveDetailSet a tag,nameSet the parameter to the name of the 'call field' you entered when customizing the field in the background. For example, if you have a custom field with a call field name ofproduct_code, then you can use:{% archiveDetail with name="product_code" %}To get its value. If you want to iterate over all custom fields, you can usearchiveParamstag, it will return an array containing all custom parameters for easy iteration display.

Related articles

How to create and manage new document tags in AnQiCMS?

As an experienced CMS website operation person in the security industry, I am well aware of the importance of content tags in website content organization and search engine optimization (SEO).AnQi CMS provides a straightforward and flexible label creation and management mechanism, aimed at helping operators efficiently classify content, improving user experience, and optimizing the website's performance in search engines. ### Understanding Document Tags in AnQi CMS In AnQi CMS, document tags are a powerful content association tool.

2025-11-06

What is the main difference between AnQiCMS document tags and document categories?

As an experienced security CMS website operator, I am well aware of the core status of content organization in website operation.In AnQiCMS, to manage and optimize content efficiently, we mainly rely on two powerful content organization tools: **Document Classification** and **Document Tags**.Although they are all intended to help us summarize and find content, there are significant differences in their design philosophy, functional focus, and actual application scenarios.The document classification plays a role in structuring content and serving as the main navigation skeleton in AnQiCMS.

2025-11-06

How to add custom field types to AnQiCMS content model?

As a professional who has been deeply engaged in AnQiCMS content operations, I am well aware of the importance of the flexibility of the content model in meeting the diverse needs of readers.AnQiCMS provides powerful custom capabilities in content management, especially its custom field function of the content model, which is the foundation for our efficient content creation and management.Below, I will explain in detail how to add custom field types to the AnQiCMS content model to help you better build personalized content structures.--- ### Adding Custom Field Types for AnQiCMS Content Model

2025-11-06

What are the naming conventions for model table names when customizing AnQiCMS content models?

In the flexible and versatile content management ecosystem of AnQiCMS, custom content models are undoubtedly the key tools for website operators to achieve personalized content display and management.It enables us to create various types of content structures such as articles, products, and cases according to business needs, thus greatly enhancing the adaptability of the system.However, while enjoying this high degree of freedom, it is particularly important to follow the naming conventions set by the system, especially when defining model table names.As an experienced AnQiCMS operator, I am well aware of these seemingly minor regulations

2025-11-06

How to use AnQiCMS template tags to get a document list (archiveList) under specified conditions?

As an experienced security CMS website operator, I am well aware of the key role of efficient content management and accurate content presentation in the success of the website.In AnQiCMS, flexibly using template tags is an important way to achieve this goal.Today, we will delve into how to use the `archiveList` template tag to retrieve and display document lists according to specified conditions, thereby meeting diverse content display needs.

2025-11-06

How to implement cross-site document data calling in AnQiCMS multi-site management?

As an experienced CMS website operation personnel of an enterprise security, I know that efficient content reuse and data integration are crucial for improving operational efficiency in multi-site management.AnQi CMS was designed with the needs of small and medium-sized enterprises, self-media operators, and users with multi-site management requirements in mind, one of its core strengths being its powerful multi-site management capabilities.This is not limited to the creation and management of independent sites, but also reflects the flexibility and convenience of cross-site document data calls.

2025-11-06

How to optimize document links for AnQiCMS's URL rewrite rule?

As an experienced website operator, I am well aware of the importance of a website's link structure for user experience and Search Engine Optimization (SEO).In the daily operation of AnQiCMS (AnQiCMS), the URL rewrite rule is one of the key tools we use to optimize document links and improve website performance.Today, I will elaborate on how AnQiCMS's pseudo-static rules can help us achieve this goal. The link to the website, like a map for users and search engines.

2025-11-06

How does AnQiCMS prevent the collection of document content and protect image copyrights?

As an experienced senior person in the field of enterprise CMS content operation, I know that content is the lifeline of the website, and the value of original content is self-evident.In this digital age, the collection of content and the infringement of image copyrights are common challenges faced by operators.Aqiy CMS is well-versed in this and has provided us with powerful tools to deal with these issues.Below, I will elaborate on how Anqi CMS builds a solid defense from both content and image levels for us.

2025-11-06