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.