In the daily operation of AnQi CMS, obtaining and displaying detailed information of website content is one of the core tasks.archiveDetailThe tag is a powerful tool specifically designed for this purpose in the Aiqi CMS template system, allowing us to flexibly extract detailed data from any specified document, including standard document properties and user-defined field content.
Deep understandingarchiveDetailThe core function of the tag
archiveDetailLabels play a crucial role in the AnQi CMS template, helping website operators display all relevant information about a single document on the page. Whether you want to load the content of the current article on the article detail page or call the data of a specific document on other pages,archiveDetailCan provide concise and efficient solutions.
The basic usage of this tag is usually{% archiveDetail with name="字段名称" %}.If the tag does not specify a variable name, it will directly output the value of the requested field.{% archiveDetail archiveItem with name="字段名称" %}and then through{{ archiveItem }}to refer to this variable.
To get the detailed information of a specific document,archiveDetailThe tag supports the following parameters:
id: By the unique digital ID of the document to specify the document to be retrieved. For example,id="1"The document with ID 1 will be retrieved. If this parameter is not specified, the tag will default to trying to retrieve the document associated with the current page.token: Specify the document through the document's URL alias (also known as URL Token). This is very useful when the URL structure is based on aliases. For example,token="my-article-slug".idSimilar, if not specified, it defaults to the current document.siteId: In the multi-site management scenario of AnQi CMS, if you need to call document data from other sites, you can specify the site ID through this parameter.Under normal circumstances, this parameter does not need to be filled in, the system will automatically identify the current site.
Access the standard field content of the document
archiveDetailTags can directly access multiple built-in standard fields of the document.This field covers the basic information such as document title, content, link, image, etc.
- Document title (}
Title):{% archiveDetail with name="Title" %}. This will directly display the title of the document. - document link (}
Link):{% archiveDetail with name="Link" %}。This is used to generate the URL pointing to the detail page of this document. - Document Description (
Description):{% archiveDetail with name="Description" %}。This is usually used to display the summary or introduction of the document. - Document content (
Content):{% archiveDetail with name="Content" %}。This is the core text content of the document. Please note when using this field.ContentSupportlazyThe parameter is used for image lazy loading, for examplelazy="data-src". In addition, if the Markdown editor is enabled,Contentthe content will be automatically converted to HTML; you can also userender=trueorrender=falseParameters manually control whether to perform Markdown to HTML conversion. To safely display HTML content, it is usually necessary to combine|safesuch as{{ articleContent|safe }}. - Document cover first image (
Logo) and Thumbnail (Thumb):{% archiveDetail with name="Logo" %}or{% archiveDetail with name="Thumb" %}They separately get the large and thumbnail images of the document, commonly used for displaying in lists or as the main visual element on a page. - Document add time (
CreatedTime):{% archiveDetail with name="CreatedTime" format="2006-01-02 15:04" %}. This field returns a timestamp and needs to be converted usingformatParameter specifies the output date and time format.
For example, the basic structure of the document title and content displayed on the document detail page can be implemented as follows:
<article>
<h1>{% archiveDetail with name="Title" %}</h1>
<div class="article-meta">
<span>发布时间:{% archiveDetail with name="CreatedTime" format="2006-01-02" %}</span>
<span>浏览量:{% archiveDetail with name="Views" %}</span>
</div>
<div class="article-content">
{% archiveDetail articleContent with name="Content" lazy="data-src" render=true %}
{{ articleContent|safe }}
</div>
</article>
Flexiblely obtain custom field content
One of the major advantages of AnQi CMS is its flexible content model, which allows operators to define unique custom fields for different types of content (such as articles, products).For the 'product' model, add fields such as 'color', 'size', 'material', and so on.archiveDetailLabels can also retrieve the content of these custom fields.
To retrieve a specific custom field, for example, you have defined a field namedauthoryou can directly display its value throughnameby calling the parameter:
<p>文章作者:{% archiveDetail with name="author" %}</p>
This method is suitable when you exactly know which custom field to call.
You can combine them when you want to dynamically traverse and display all custom fields in the document.archiveParamsLabel.archiveParamsLabel can retrieve all custom parameters of the current document or a specified document and organize them into an iterable array object.
The following is an example that demonstrates all custom fields.
{% archiveParams params %}
<div class="custom-fields">
{% for item in params %}
<p>
<strong>{{ item.Name }}:</strong>
<span>{{ item.Value }}</span>
</p>
{% endfor %}
</div>
{% endarchiveParams %}
In the above code,paramsisarchiveParamsLabel gets the set of custom fields. EachitemincludingName(field display name) andValue(field value). If your custom field stores an image path, for example, a field namedproduct_galleryThe custom field is used to store product group images, you can iterate and display the images like this:
{% archiveDetail productGallery with name="product_gallery" %}
{% if productGallery %}
<div class="product-images">
{% for image in productGallery %}
<img src="{{ image }}" alt="产品图片">
{% endfor %}
</div>
{% endif %}
Here it is assumedproduct_galleryThe type of the custom field is 'Multi-image upload' or 'Multi-line text' and stores multiple image URLs.In practical applications, the type of a custom field affects the way its value is displayed, so it needs to be handled according to the actual situation in the template.
PassarchiveDetailandarchiveParamsTags, A safe CMS provides powerful content display capabilities for website operators. Whether it is standard document information or customized fields for specific business needs, they can be accurately acquired and rendered, greatly enhancing the flexibility and customization of the website.
Common Questions and Answers (FAQ)
1.archiveDetailLabel can be obtained on the document list page whether it can get detailed information of the specified document?Yes,archiveDetailLabel can obtain detailed information of the specified document on any page. You just need to go throughidortoken参数明确指定要获取的文档即可。例如,{% archiveDetail with name="Title" id="10" %}可以在列表页获取ID为10的文档标题,而不会影响当前列表的循环。
2. 为什么我使用{% archiveDetail with name="Content" %}Did the content obtained not display the HTML style correctly or did the Markdown conversion fail?
ContentThe field usually retrieves raw text or a string containing HTML tags. If the content contains HTML, you need to use|safeA filter to indicate that the template engine should not escape it, for example{{ archiveContent|safe }}If the content is in Markdown format and is expected to be automatically converted to HTML, please make sure that the Markdown editor is enabled in the background content settings, or explicitly add it in the tagrender=trueParameter.
3. How to determine if a custom field exists or has a value to avoid displaying empty content on the page?When you assign a value of a custom field to a variable, you can useifLogical judgment label to check if the variable exists or is empty. For example, if you have a custom fieldproduct_dimensions:{% archiveDetail dimensions with name="product_dimensions" %}
{% if dimensions %}
<p>产品尺寸:{{ dimensions }}</p>
{% endif %}This ensures that related content is only displayed when the field has a value.