As an experienced CMS website operation person, I know well the core position of content in website operation.We must not only create high-quality content, but also ensure that this content is presented to users in an **English** manner.This is where the flexible use of templates is crucial.archiveDetailIt can help us easily obtain the detailed information of the document, including those carefully designed custom fields.
UnderstandingarchiveDetailThe core function of the tag
In AnQiCMS,archiveDetailTags are important tools used to obtain all detailed data of specific documents (such as articles, products, etc.) in templates. Whether it is to display the content of the current page's document or to obtain data from other specified documents as needed,archiveDetailEverything needed can be provided.It defaults to retrieving information about the currently accessed document, but by setting simple parameters, we can also accurately capture data from any document on the site.
The basic usage of this tag usually includes specifying a variable name to store the obtained data, and usingnameThe parameter is used to specify the specific fields to be retrieved. If the variable name is not specified, the tag will directly output the field values of the request.
archiveDetailCommon parameters of the tag.
archiveDetailThe flexibility of the tag is reflected in its supported parameters. In addition to the default retrieval of the current document, it also allows for precise control of the data source through the following parameters:
- 文档 ID (English)
id)This is an optional parameter used to get the details of the document with the specified ID.When you need to display document data that is not on the current page, such as recommended articles in the sidebar, you can use this parameter. - Document URL alias (}]
token): withidis similar,tokenUsed to specify the document. If you are more familiar with the document's URL alias (usually pinyin or a custom short link), you can use this parameter. - Site ID (
siteId):For users who use the AnQiCMS multi-site management function,siteIdIt can help you call data across sites. If your website is a single-site architecture, this parameter is usually not necessary.
The clever combination of these parameters makesarchiveDetailCan adapt to various complex template requirements.
Get standard field information of the document.
archiveDetailTags can return multiple standard fields of documents, which cover the basic attributes, SEO information, and media content of documents. The following are some common available fields and their usage examples:
文档 ID (English)
Id) and the title (Title) and the link (Link) and the description (Description)These are the most basic and most commonly used information.{# 获取当前文档的标题 #} <h1>{% archiveDetail with name="Title" %}</h1> {# 获取指定ID文档的链接 #} <a href="{% archiveDetail with name="Link" id="10" %}">查看详情</a> {# 将文档描述赋值给变量并使用 #} {% archiveDetail docDesc with name="Description" %}<meta name="description" content="{{docDesc}}">Document content (
Content)This is the main content of the document. It is noteworthy that,ContentField supports additional properties to handle image lazy loading and Markdown rendering.- Image lazy loading (
lazy): If your website uses a lazy loading plugin, you can uselazy="data-src"etc.imgTagssrcProperty replacement for the properties required by the plugin. - Markdown Rendering (
render): When the Markdown editor is enabled in the background, the content will be automatically rendered. You can also userender=trueorrender=falseManual control whether to convert Markdown to HTML.
{# 获取当前文档内容,并处理图片懒加载和Markdown渲染 #} {% archiveDetail docContent with name="Content" lazy="data-src" render=true %}{{docContent|safe}} {# `|safe`过滤器用于避免HTML实体转义,确保内容正确显示 #}- Image lazy loading (
Views (
Views)、Comment count (CommentCount): Used to display interactive data of the document.<span>浏览量:{% archiveDetail with name="Views" %}次</span>Cover image (
Logo/Thumb/Images):LogoUsually refers to a large image,Thumbwhile referring to a thumbnail,ImagesThen it may be an image array, used to display a group of images.{# 获取文档Logo #} <img src="{% archiveDetail with name="Logo" %}" alt="{% archiveDetail with name="Title" %}"> {# 循环输出文档组图 #} {% archiveDetail docImages with name="Images" %} <ul> {% for img in docImages %} <li><img src="{{img}}"></li> {% endfor %} </ul>Creation time (
CreatedTime), Update time (UpdatedTime): These fields return timestamps and need to be coordinated withformatparameters orstampToDatea filter for formatting.<span>发布日期:{% archiveDetail with name="CreatedTime" format="2006-01-02 15:04" %}</span> {# 或者使用变量和过滤器 #} {% archiveDetail createdTime with name="CreatedTime" %}{{stampToDate(createdTime, "2006年01月02日")}}Document category (
Category):This field returns an object containing classification information. You can directly access its properties, or consider usingcategoryDetailtags to get more comprehensive classification information.{% archiveDetail docCategory with name="Category" %} <p>所属分类:<a href="{{docCategory.Link}}">{{docCategory.Title}}</a></p>document tags (Tag)Although
archiveDetailIt does not directly return the label list, but you can get the related labels after obtaining the document ID, combinedtagListwith tags.{% archiveDetail currentDocId with name="Id" %} {% tagList tags with itemId=currentDocId %} {% for tag in tags %} <a href="{{tag.Link}}">{{tag.Title}}</a> {% endfor %} {% endtagList %}
Get the custom field information of the document.
AnQiCMS powerful flexible content model allows us to define exclusive custom fields for different types of documents. These custom fields can also bearchiveDetailTags can be used to get, which greatly enhances the customization capabilities of the template.
If you know the name of the custom field explicitly (for example, you have defined a field named in the content model)authorThe field (can be accessed directly throughnamecan be invoked by the parameter:
{# 获取自定义字段“author”的值 #}
<p>作者:{% archiveDetail with name="author" %}</p>
Further more, if you need to iterate through all custom fields or are unsure of the specific names of all fields, you can usearchiveParamsLabel. It will return all custom fields as an array object, convenient for you to loop display:
{% archiveParams params %}
<div>
{% for item in params %}
<p>
<span>{{item.Name}}:</span> {# 字段的显示名称 #}
<span>{{item.Value}}</span> {# 字段的值 #}
</p>
{% endfor %}
</div>
Combined with specific business scenarios, for example, a product model defines a namedspecificationsThe custom field, whose value is a piece of HTML code or a JSON string, can be handled in the template like this:
{% archiveDetail productSpecs with name="specifications" %}<div class="product-specs">{{productSpecs|safe}}</div>
Or ifarcimagesis a custom grouping field, you can display it like this:
{% archiveDetail customImages with name="arcimages" %}
<div class="custom-gallery">
{% for imgUrl in customImages %}
<img src="{{imgUrl}}" alt="产品图">
{% endfor %}
</div>
details display of the document in practical application
PassarchiveDetailThe combination of related tags can help us easily build a feature-rich and comprehensive document detail page.
Consider a typical article detail page, which needs to display the article title, category, publish time, associated tags, reading volume, and article content. The template code may look something like this:
<article>
<h1>{% archiveDetail with name="Title" %}</h1>
<div class="meta-info">
{% archiveDetail currentCategory with name="Category" %}
<span class="category-link"><a href="{{currentCategory.Link}}">{{currentCategory.Title}}</a></span>
<span>发布于:{% archiveDetail with name="CreatedTime" format="2006-01-02" %}</span>
{% archiveDetail currentDocId with name="Id" %}
{% tagList tags with itemId=currentDocId %}
<span class="tags">标签:
{% for tag in tags %}<a href="{{tag.Link}}">{{tag.Title}}</a> {% endfor %}
</span>
{% endtagList %}
<span>阅读:{% archiveDetail with name="Views" %}次</span>
</div>
<div class="article-content">
{% archiveDetail articleBody with name="Content" render=true lazy="data-src" %}{{articleBody|safe}}
</div>
</article>
而对于一个产品详情页,除了产品名称和图片,通常还需要展示其特有的参数、简介和详细描述。如果我们在产品模型中定义了brand(Brand),model(Model) etc. custom fields, the template can be implemented as follows:
<div class="product-detail-container">
<div class="product-media">
<img src="{% archiveDetail with name="Logo" %}" alt="{% archiveDetail with name="Title" %}" class="main-product-image">
{% archiveDetail galleryImages with name="Images" %}
<div class="product-gallery">
{% for img in galleryImages %}<img src="{{img}}">{% endfor %}
</div>
</div>
<div class="product-info">
<h1>{% archiveDetail with name="Title" %}</h1>
<p class="product-description">{% archiveDetail with name="Description" %}</p>
<div class="product-specs">
<h3>产品参数</h3>
{% archiveParams productParams %}
<ul>
{% for item in productParams %}
<li><strong>{{item.Name}}:</strong>{{item.Value}}</li>
{% endfor %}
</ul>
{% endarchiveParams %}
</div>
<div class="full-description">
<h3>详细介绍</h3>
{% archiveDetail productContent with name="Content" render=true %}{{productContent|safe}}
</div>
</div>
</div>
Summary
archiveDetailLabels are an indispensable tool in the development of AnQiCMS templates.It provides an intuitive and powerful way to access and display various information of documents, whether it is built-in standard fields or customized fields according to business needs.Proficient in its usage and parameters will give you a high degree of freedom and efficiency in presenting website content, ensuring that every piece of content is presented to your users in the most perfect state.
Frequently Asked Questions
Why are my custom fields not displayed in the template?Ensure that you have correctly defined these custom fields in the content model of AnQiCMS backend and filled in the content for them when publishing documents. Additionally, check the template for custom fields.nameThe parameter is whether it is completely consistent with the "called field" name defined by the background, and pay attention to the case.AnQiCMS's template tags are case-sensitive.nil,it may not output any content, you can use filters likedefaultto set default values for troubleshooting.
How can I get more information about the category of the current document, such as the category's Logo or Banner image?When you go through{% archiveDetail docCategory with name="Category" %}After obtaining the category object of the document,docCategoryThe variable includes all properties of the category, such asdocCategory.Link/docCategory.Title. If you need to get the categoryLogoorBannergraph, you can use it directlydocCategory.LogoordocCategory.Images. If you need to get more complex custom fields of the category or do not want to rely onarchiveDetailGet the classification object, you can also usecategoryDetailTags, through{% categoryDetail with name="Logo" id=docCategory.Id %}to get more details of the specified ID classification.
Why is mine?ContentThe field displays HTML code or Markdown syntax, not the rendered content?IfContentThe field displays the original HTML code, which may be because you have not used|safeFilter. AnQiCMS for security reasons, will automatically escape HTML tags,|safeThe filter informs the template engine that this is safe content and does not require escaping. If the displayed content is Markdown syntax, it may be that the Markdown editor is not enabled on the back end, orarchiveDetailLabel is not setrender=trueParameters to force Markdown to HTML conversion. Please add according to your needs.|safefilters andrenderParameter.