Manage and display website content in AnQiCMS,archiveDetailTags are undoubtedly one of the core tools. They allow us to delve into each specific document, whether it is an article, product, or other custom type, thus extracting and presenting its detailed information, even including those custom fields tailored to business needs.Understand and flexibly apply this tag to make our website content more accurate and rich.
archiveDetailBasic and advanced usage of tags
When we are on a document detail page, AnQiCMS will automatically identify the ID of the current document. At this time, to obtain the title or content of the document, it is usually possible to directly use such as{{archive.Title}}or{{archive.Content}}Such a variable. However,archiveDetailTags provide more powerful control, especially when it is necessary to specify a particular document or to retrieve its specific fields.
UsearchiveDetailThe basic syntax of tags is:{% archiveDetail 变量名 with name="字段名称" %}. The variable name is optional, you can omit it if you directly retrieve and output the content within the tag;But if you want to assign the obtained value to a variable for subsequent reuse or more complex logic processing, specifying a variable name will be very convenient.
Two ways to specify a document:
archiveDetailTags are not limited to the current page. If we need to display the content of a specific ID document, or obtain it based on its URL alias (token), we can do so byidortokenTo implement the parameter. For example, if you want to get the ID of1the document title, you can write it like this:{% archiveDetail with name="Title" id="1" %}.
Data call in multi-site environment:For AnQiCMS systems deployed at multiple sites, if you need to call data from other sites in the current site,siteIdParameters come into play. By specifying the ID of the target site, we can retrieve content across sites, which is very useful for resource integration or displaying related content.
Delve into the standard fields of the document
Each document of AnQiCMS includes a series of standard fields such as title, content, link, views, creation time, and so on.archiveDetailLabels allow us to accurately obtain this information one by one.
- Document title (
Title) and description (Description):This is the most basic display element. For example,{% archiveDetail with name="Title" %}Can retrieve the title of the current document. - Document content (
Content):This is the core part of the document. It is worth noting that if the document content contains HTML tags, in order to ensure that they are parsed correctly by the browser rather than displayed as plain text, we need to use them in conjunction with.|safea filter such as{{archiveContent|safe}}In addition, if your document uses a Markdown editor,ContentThe field supports passing throughrender=truethe parameter is rendered as HTML on the front end, providing a more flexible way to display. - Image resources (
Logo,Thumb,Images):Documents are usually accompanied by cover images or sets of images.LogoIt usually refers to the first image on the cover,Thumbwhich is a thumbnail, whereasImagesit may be a set of images. When obtainingImagesIt will return an array of image URLs whenforLoop to traverse and display all images. - Time information (
CreatedTime,UpdatedTime):The creation and update time of the document can clearly show the freshness of the content.archiveDetailTags allow you to go throughformatParameters are formatted directly against the timestamp, for example{% archiveDetail with name="CreatedTime" format="2006-01-02 15:04" %}This allows us to display the date and time in the format we are accustomed to. - Views (
Views):This is a direct and intuitive indicator of the popularity of content, which can be obtained and displayed to users. - Category of the document (
Category):ByarchiveDetailThe document object obtained contains detailed information about its category. We can use this information or combinecategoryDetailtags to display category names and links, enhancing the navigation of the content.
Make flexible use of custom fields to create exclusive content display
The strength of AnQiCMS lies in its 'flexible content model' feature, which allows us to customize document fields according to business needs.These custom fields are the key to achieving "fine-grained" content display.
In the background content model settings, we can add various types of custom fields to models such as articles, products, etc., such as "author", "source", "product parameters", "additional albums", and so on. Once these fields are defined and filled with content, we can use them in templates byarchiveDetailtags to get them.
Retrieve all custom fields:If you want to iterate over all custom fields and their values in a document,archiveParamsLabels are an ideal choice. It will return an array object containing field names and values, which we can use to dynamically display throughforcycles, which is very practical in scenarios such as product parameter lists.
{# 假设我们有一个名为'product'的产品模型,其中定义了自定义参数 #}
{% archiveParams params %}
<div>
{% for item in params %}
<div>
<span>{{item.Name}}:</span>
<span>{{item.Value}}</span>
</div>
{% endfor %}
</div>
{% endarchiveParams %}
Accurately retrieve specific custom field:It is more common and flexible to directly obtain the content through the "calling field name" of a custom field (i.e., the lowercase English field name used when defined in the background). For example, if you have customized a field namedauthorThe field can be directly called like this:
<div>作者:{% archiveDetail with name="author" %}</div>
If the custom field is an image group (such as a namedproduct_galleryfield), it will also return an array of URLs that need to be displayed in a loop:
{% archiveDetail productGallery with name="product_gallery" %}
<div class="product-images">
{% for imgUrl in productGallery %}
<img src="{{imgUrl}}" alt="产品图片" />
{% endfor %}
</div>
Combine an example to create a rich detail page
By combining the above features, we can easily create a detailed document page that is rich in content and clear in structure.
A typical article detail page structure may include:
- Article title:
<h1>{% archiveDetail with name="Title" %}</h1> - Publishing information:
- Category links and names:
分类:<a href="{% categoryDetail with name='Link' %}">{% categoryDetail with name='Title' %}</a> - Published time:
发布于:{% archiveDetail with name="CreatedTime" format="2006年01月02日" %} - Views:
阅读量:{% archiveDetail with name="Views" %} - Tags through related tags:
tagListTags cycle to display the tags of the current document.
- Category links and names:
- Article content:
<div>{% archiveDetail content with name="Content" %}{{content|safe}}</div>
And a product detail page may need:
- Product main image:
<img src="{% archiveDetail with name='Logo' %}" alt="{% archiveDetail with name='Title' %}" /> - Product name:
<h2>{% archiveDetail with name="Title" %}</h2> - Product parameters (custom fields): using
archiveParamsTag loop display all parameters, or accurately call specific parameters such as{% archiveDetail with name="color" %}. - Product Introduction:
<p>{% archiveDetail with name="Description" %}</p> - Product detailed description:
<div>{% archiveDetail productContent with name="Content" %}{{productContent|safe}}</div> - Contact information: can be combined
contactTags directly display phone numbers or WeChat and other.
By this means,archiveDetailTags are not only tools for obtaining document content, but also the foundation for the flexible customization and refined operation strategy of AnQiCMS.
Frequently Asked Questions (FAQ)
Can I use it on non-document detail pages?
archiveDetailAm I supposed to use the label?Of course you can.archiveDetailOne of the main advantages of tags is their flexibility. As long as you know the ID of the target document or its URL alias (token), you can access it on any page of the website - whether it's the homepage, a list page, or any other single page - byidortokenHow to specify and retrieve the detailed content of a document. For example, to display a complete detail of a 'recommended article' on the homepage, you can specify its ID.How to ensure passing
archiveDetailThe HTML content obtained (such asContentfield) is displayed safely to avoid XSS risks?AnQiCMS's template engine encodes all output variables by default with HTML entities to prevent XSS attacks. But when you need to display rich text content in the document (such asContentfield), these contents themselves contain HTML tags when|safeThe filter tells the template engine that this part of the content is safe, no encoding is needed, and it can be output directly as HTML.Although this provides flexibility, it also means that you need to ensure that the content entered into these fields is trustworthy, or that strict filtering and validation of user input has been performed on the backend to minimize potential risks.**If my custom field is a long text but only want