As an experienced AnQi CMS website operation personnel, I am well aware that content is the core of the website, and how to efficiently and accurately present 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 function of the tag
In AnQiCMS, whether it is articles, products, or other custom model content, we all call it 'documents' (archive).archiveDetailThe core function of the tag is to retrieve and display the detailed information of a single document in the template.It allows us to precisely specify which document's fields of data to retrieve, thus meeting various content display needs.
In most cases, when we visit the detail page of a document, AnQiCMS will automatically identify the document ID of the current page, at which point we do not need to specify the ID additionally.archiveDetail
archiveDetailBasic Usage and Parameter Parsing
archiveDetailThe usage of tags is very intuitive, and 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 fields you want to retrieve from the document. For example,name="Title"will retrieve the document title,name="Content"will retrieve the document content.id="文档ID"If you want to get a document that is not currently displayed on the page, but a document with a specific ID in the site, you can specify this parameter. For example,id="10"Retrieve data of the document with ID 10.token="文档URL别名": withidSimilarly, you can also specify a 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, as the system will default to fetching the 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, loops, or displaying multiple fields together), you can define a variable name here.nameThe value specified by the parameter.
Call example of common fields
archiveDetailTags can access various built-in fields of the document. Here are some of the fields and calling methods that our operations team uses most often:
Document title (}Title)
This is the core of any content page. Throughname="Title"you can easily display the title of the document.
{# 直接输出当前文档标题 #}
<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 fields also support two important properties:
lazy="data-src"If you have used a lazy loading plugin for images, you can use this property to<img>Tagssrcattribute in the content withdata-srcto optimize the 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 require conversion, 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 output content includes HTML tags, it is usually necessary to add|safea filter to prevent HTML from being escaped and unable to display correctly.
document link (}Link)
Retrieve the URL link of the document, commonly used for building navigation or related recommendations.
<a href="{% archiveDetail with name="Link" %}">阅读更多</a>
Document creation time (CreatedTime) and update time (UpdatedTime)
These fields return timestamps and require coordination withformatParameter formatting for display. AnQiCMS follows the Go language rules for time formatting, for example"2006-01-02"indicates 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[en]: Usually used to obtain the main image or large image of the document.Thumb[en]: Used to obtain 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 category (Category)
Get the classification information of the document. This field will return an object containing properties such as classification ID, title, link, etc.
{% archiveDetail docCategory with name="Category" %}
<p>分类:<a href="{{ docCategory.Link }}">{{ docCategory.Title }}</a></p>
Custom fields of the document
The AnQiCMS content model allows us to add custom fields such as "author", "source", or "product parameters." These custom fields can be directly accessed via their defined "call field" names in the backend.nameParameters can be obtained.
Suppose you have a custom field, the name of the field isauthor:
<p>作者:{% archiveDetail with name="author" %}</p>
If you want to display all custom fields, especially those that are not fixed, you can usearchiveParamsTag to cycle display.
{# 在文档详情页,循环显示所有自定义参数 #}
{% archiveParams customFields %}
{% for param in customFields %}
<p>{{ param.Name }}:{{ param.Value }}</p>
{% endfor %}
{% endarchiveParams %}
Application based on actual scenarios.
Suppose we need to display a related 'User Guide' article in the sidebar in addition to the detailed information of the product on the product detail page.
{# 产品名称 #}
<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>
PassarchiveDetailThe flexible application of tags allows us to precisely control the content displayed on each page, achieving a highly customized front-end display effect, thereby better attracting and retaining users.Mastering this tag is a key step for efficient content operation on AnQiCMS.
Common Questions and Answers (FAQ)
Question: How can I get all information of the current document in a template, not just a single field?
Answer:archiveDetailTags are mainly used to get the value of a single field. If you want to get the entire data object of the current document and assign it to a variable so that it can be used more flexibly in the template (for example,{{archive.Title}}/{{archive.Link}}[en] You usually do not need to explicitly usearchiveDetailtags 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 namedarchivea global variable. You can directly access its properties through{{ archive.字段名 }}. If you indeed need to accessarchiveDetailGet the entire object, which usually requires tonameParameters are left blank, and the entire data is assigned to a variable, but this usage is rarely directly used to obtain all fields, more often for internal transmission mechanisms.
Question: 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 callsname="Content"you can addrender=trueparameters to indicate that the system should convert Markdown content to HTML. For example:{% archiveDetail with name="Content" render=true %}[en] At the same time, to ensure that the converted HTML can be correctly parsed by the browser rather than displayed as plain text, you usually also need to add|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. In your usagearchiveDetailwillnameSet the parameter to the 'Call Field' name you entered when customizing fields in the background. For example, if you have a custom field with a call field name ofproduct_code, you can use it as{% archiveDetail with name="product_code" %}Get its value. If you want to iterate over all custom fields, you can usearchiveParamsa tag that will return an array containing all custom parameters, making it convenient for you to loop and display.