How to use AnQiCMS's `archiveDetail` tag to refine the acquisition and display of detailed content and custom fields for specified documents?

Manage and display website content in AnQiCMS,archiveDetailTags are undoubtedly one of the core tools.It allows us to delve into each specific document, whether it is an article, product, or other custom type, thus extracting and presenting its detailed information, including those custom fields tailored to business needs.Understand and flexibly use this tag to make our website content display more accurate and rich.

archiveDetailBasic and advanced usage of tags

When we are on the detail page of a document, AnQiCMS will automatically identify the ID of the current document. At this time, to get 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. If you directly get and output the content inside the tag, you can omit it; 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.

Specify the document in two ways: archiveDetailLabels 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 canidortokenParameters can be used to achieve this. For example, if you want to get the ID of1Document title, you can write it like this:{% archiveDetail with name="Title" id="1" %}.

Data call in a multi-site environment:For AnQiCMS system deployed with multiple sites, if you need to call data from other sites in the current site,siteIdParameters come into play. By specifying the target site's ID, we can retrieve content across sites, which is very useful for resource integration or displaying related content.

Deeply explore the standard fields of the document

Each document of AnQiCMS includes a series of standard fields, such as title, content, link, views, creation time, etc.archiveDetailLabels can help us 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 get the current document title.
  • 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 can be parsed correctly by the browser rather than displayed as plain text, we need to use them in conjunction with.|safeFilters such as{{archiveContent|safe}}. In addition, if your document uses a Markdown editor,Contentthe field also supports being rendered as HTML through therender=trueparameter, providing a more flexible way to display.
  • Image resources (Logo,Thumb,Images):Documents usually come with a cover image or a series of images.LogoIt usually refers to the cover image,ThumbIt is a thumbnail, whileImagesit may be a set of images. When accessingImagesWhen, it will return an array of image URLs, at this time, it is necessary to traverse and display all images byfora loop.
  • time information (CreatedTime,UpdatedTime):The creation and update time of the document can clearly show the 'freshness' of the content.archiveDetailTags allow you toformatFormat the timestamp directly, for example{% archiveDetail with name="CreatedTime" format="2006-01-02 15:04" %}This can be displayed in the date and time format we are accustomed to.
  • Views (Views):This is a direct measure of how popular the content is, which can be easily obtained and displayed to users.
  • Document Category (Category):byarchiveDetailThe document object obtained contains its detailed category information. We can use this information, or combinecategoryDetailTags, display category names and links, enhancing the navigation of content.

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 based on business needs.These custom fields are the key to realizing 'refined' 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 galleries", etc. Once these fields are defined and filled with content, we can use them in templates.archiveDetailLabel to get them.

Get all custom fields:If you want to iterate over all custom fields and their values in a document,archiveParamsLabels are a good choice. It returns an array object containing field names and values, which we can iterate over to dynamically display, which is very practical in scenarios such as product parameter lists.forThis 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 fields:The more common and flexible approach is to directly obtain the content through the 'called field name' of the custom field (i.e., the lowercase field name used when defining it in the background). For example, if you have customized a field namedauthorThe field can be accessed directly like this:.

<div>作者:{% archiveDetail with name="author" %}</div>

If the custom field is an image group (such as a field named)product_galleryThe field) it will also return an array of URLs, which needs 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 examples to build rich detail pages

By combining the above features, we can easily build content-rich and well-structured document detail pages.

A typical article detail page structure may include:

  • Article title:<h1>{% archiveDetail with name="Title" %}</h1>
  • Publishing information:
    • Category link and name:分类:<a href="{% categoryDetail with name='Link' %}">{% categoryDetail with name='Title' %}</a>
    • Publishing time:发布于:{% archiveDetail with name="CreatedTime" format="2006年01月02日" %}
    • Page views:阅读量:{% archiveDetail with name="Views" %}
    • Tags: ThroughtagListTags are displayed in a loop for the current document.
  • Article content:<div>{% archiveDetail content with name="Content" %}{{content|safe}}</div>

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): UtilizearchiveParamsTags display all parameters in a loop, or call specific parameters such as{% archiveDetail with name="color" %}.
  • Product Description:<p>{% archiveDetail with name="Description" %}</p>
  • Product detailed description:<div>{% archiveDetail productContent with name="Content" %}{{productContent|safe}}</div>
  • Contact information: can be combinedcontactTags directly display phone or WeChat, etc.

Through this method,archiveDetailLabels are not only tools to obtain document content but also the cornerstone of AnQiCMS flexible customization and refined operation strategies.


Common Questions (FAQ)

  1. Can I usearchiveDetailLabels on non-document detail pages?Of course, you can.archiveDetailOne of the main advantages of the label is its flexibility. As long as you know the ID or the URL alias (token) of the target document, you can access it on any page of the site - whether it's the homepage, a list page, or any other single page - byidortokenHow to specify and retrieve the detailed content of the document. For example, to display a full detail of a 'Recommended Article' on the homepage, you can specify its ID.

  2. How to ensure thatarchiveDetailRetrieved HTML content (such asContentfield) is safely displayed, avoiding XSS risk?AnQiCMS template engine encodes all output variables by default as HTML entities to prevent XSS attacks. But when you need to display rich text content in the document (such asContentField), these contents themselves include HTML tags, in which case you need to use|safeThe filter tells the template engine that this part of the content is safe, does not need to be encoded, and 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.

  3. **If my custom field is a long text but I only want