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 in the Anqi CMS template system, specifically designed for this purpose, allowing us to flexibly extract detailed data from any specified document, including standard document attributes and user-defined field content.
Deep understandingarchiveDetailThe core function of the tag
archiveDetailTags play a crucial role in Anqi CMS templates, helping website operators display all relevant information for a single document on the page. Whether you want to load the content of the current article on the article detail page, or call data for 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.When you need to store the document data you have obtained into a variable for subsequent complex processing or conditional judgment, you can use it in this way:{% archiveDetail archiveItem with name="字段名称" %}Then proceed{{ archiveItem }}to refer to the variable.
To obtain the detailed information of a specific document,archiveDetailThe tag supports the following parameters:
id: Specify the document to retrieve by its unique numeric ID. 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: By specifying the document URL alias (also known as URL Token) to identify the document. This is very useful when the URL structure is based on aliases. For example,token="my-article-slug". AndidSimilar, if not specified, it will default to the current document.siteIdIn 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.In most cases, this parameter does not need to be filled in, the system will automatically identify the current site.
Access the standard fields of the document.
archiveDetailThe tag can directly access multiple built-in standard fields of the document.These fields cover the basic information such as document title, content, links, images, etc.Here are some commonly used standard fields and their usage examples:
- Document title (
Title):{% archiveDetail with name="Title" %}. This will directly display the title of the document. - Document link (
Link):{% archiveDetail with name="Link" %}. Used to generate the URL pointing to the document detail page. - Document description (
Description):{% archiveDetail with name="Description" %}. Usually used to display the abstract 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 lazy loading of images, 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=falseThe parameter manually controls whether to perform Markdown to HTML conversion. To safely display HTML content, it is usually necessary to combine|safefilter, such as{{ articleContent|safe }}. - Document cover first image (
Logo) and thumbnail (Thumb):{% archiveDetail with name="Logo" %}or{% archiveDetail with name="Thumb" %}. They retrieve the large image and thumbnail of the document, commonly used for displaying in lists or as the main visual element on the page. - Document added time (
CreatedTime):{% archiveDetail with name="CreatedTime" format="2006-01-02 15:04" %}. This field returns a timestamp, which needs to be processed throughformatThe parameter specifies the output date and time format.
For example, the basic structure to display the document title and content 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 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 example, add fields such as 'color', 'size', 'material', and others to the 'product' model.archiveDetailTags can also retrieve the content of these custom fields.
To get a specific custom field, for example, you have defined a field named in the background.authorThe custom field can be accessed directlynameto call with parameters:
<p>文章作者:{% archiveDetail with name="author" %}</p>
This method is suitable when you exactly know which custom field to call.
You can combine it when you want to dynamically iterate and display all custom fields of the document.archiveParams.archiveParamsThe tag can retrieve all custom parameters of the current document or a specified document and organize them into an iterable array object.
Here is an example of displaying 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,paramsIt is througharchiveParamsThe set of custom fields obtained from the tag. EachitemincludeName(field display name) andValue(field value). If your custom field stores an image path, for example, a file namedproduct_galleryThe custom field is used to store the product group image, you can traverse and display the image 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 %}
Assuming this hereproduct_galleryThe field type is 'Multiple Image Upload' or 'Multi-line Text' and stores multiple image URLs.In practice, the type of a custom field affects how its value is displayed, so it needs to be handled according to the actual situation in the template.
ByarchiveDetailandarchiveParamsThe tag, AnQi CMS provides powerful content display capabilities for website operators, whether it is standard document information or customized fields for specific business needs, all can be accurately obtained and rendered, greatly enhancing the flexibility and customizability of the website.
Frequently Asked Questions (FAQ)
1.archiveDetailCan the tag retrieve the detailed information of the specified document on the document list page?Yes,archiveDetailThe tag can retrieve the detailed information of the specified document on any page. You just need to go throughidortokenSpecify the parameter to obtain the document clearly. For example,{% archiveDetail with name="Title" id="10" %}You can get the document title with ID 10 on the list page without affecting the loop of the current list.
2. Why do I use{% archiveDetail with name="Content" %}The content retrieved did not display HTML style or Markdown conversion failed?
ContentThe field usually retrieves raw text or strings 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 you expect it to be automatically converted to HTML, make sure the Markdown editor is enabled in the background content settings, or explicitly add it in the tagrender=trueParameter.
How to determine if a custom field exists or has a value to avoid displaying empty content on the page?When you assign the 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 displayed only when the field has a value.