In the template world of AnQi CMS, efficiently and flexibly displaying content is the key to the success of website operation.We know that a good content management system not only needs to manage standardized information but also needs to adapt to the ever-changing business needs and provide personalized content display.archiveParamsIt is the silent hero behind the high degree of content customization.
In the AnQiCMS templatearchiveParamsWhat is the core role of tags?
archiveParamsLabels play a bridge role in AnQiCMS templates. It safely and flexibly presents the additional parameters customized for articles (or any document type, such as products) in the background, on the front-end page. In short, when you define personalized information such as 'color', 'size', 'author', 'origin', 'product specifications' for articles, products, or other 'documents' in the content model of the background, in addition to standard fields such as title, content, and categories.archiveParamsThis is the core tool that extracts and displays these custom data on the page.
Imagine if AnQiCMS only allows displaying fixed titles and content, then when creating e-commerce product pages, real estate information pages, or job posting detail pages, it would not be possible to display those key, differentiated attributes.archiveParamsThe appearance of [auto] has completely broken through this limit, endowing the content model with infinite extensibility. It allows you to create unique and rich attribute sets for each type of document according to your actual business needs, and through this tag, you can accurately call and layout these information in the front-end template.
The source of these custom parameters is usually AnQiCMS backendContent Modelis defined inCustom fieldsFor example, you can add a custom field named "Product Weight" of type "Number" to the "Product Model". When editing a product, you can fill in its weight.archiveParamsThe task is to extract the value of “product weight” from the background database and use it in your template.
Deep understandingarchiveParams: Parameters and Usage
archiveParamsThe basic usage of the tag is{% archiveParams 变量名称 with 参数... %}...{% endarchiveParams %}。It accepts several key parameters to control the way data is retrieved and organized:
idParameters- Function: Used to specify the custom parameters for the document to be retrieved.
- Usage:
id="1". - Description: Generally speaking, when you use
archiveParamswithout manual specificationidIt will default to getting the document ID of the current page. But if you need to display a custom parameter for a specific document on another page (such as a module on the homepage), you can do so byidParameter is explicitly specified.
sortedParameters- Function: Determines the data structure of the returned dataOrdered arrayOrUnordered map (Map).
- Usage:
sorted=trueorsorted=false. - Description:
- When
sorted=truewhen set to (default value),archiveParamsIt will return an ordered array containing custom parameters. Each array element is an object, containingName(Parameter name, such as "color") andValueTwo properties, such as "red".This method is very suitable for the scenario where you want to traverse and display all custom parameters, especially when you are not sure about the custom parameters or they may change dynamically. - When
sorted=falsewhenarchiveParams会返回一个无序的映射(类似于字典),其中键是自定义字段的“调用字段”(在后台内容模型中定义,通常是英文小写),值是包含NameandValueThe object. The advantage of this method is that if you know the specific field name of a custom parameter, you can directly access its value by the field name, without the need to traverse, which is more efficient.
- When
siteIdParameters- Purpose: In the multi-site management scenario, specify which site's document data to retrieve.
- Usage:
siteId="1". - Description: This parameter is usually not required for single-site users. If you manage multiple AnQiCMS sites and wish to call the document parameters of another site in a template of one site,
siteIdIt becomes very useful.
Application scenarios and code examples
Let's feel it through specific code snippets.archiveParamsOf the powerful functions.
Scenario one: Traverse and display all custom parameters (such as all specifications of the product)This is applicable to the product details page, where you want to list all the features or specifications of the product.
{# 假设我们正在一个文档详情页,并且后台为该文档定义了“颜色”、“尺寸”、“材质”等自定义字段 #}
<div>
<h3>产品详细参数:</h3>
{% archiveParams params with sorted=true %} {# 使用默认的 sorted=true 返回有序数组 #}
<ul>
{% for item in params %} {# 遍历数组中的每一个自定义参数 #}
<li>
<strong>{{ item.Name }}:</strong> {{ item.Value }}
</li>
{% endfor %}
</ul>
{% endarchiveParams %}
</div>
This code will intelligently traverse all custom fields, regardless of how many you add in the background, the frontend can automatically adapt and display them, greatly reducing the cost of template maintenance.
场景二:Directly access specific custom parameters (e.g., getting the 'author' information of a product)If you know exactly which specific custom field value you need to display, such as the 'author' of an article or the 'stock' of a product.
{# 方法一:通过 archiveParams with sorted=false 获取映射并直接访问 #}
{% archiveParams customFields with sorted=false %}
{% if customFields.author %} {# 假设自定义字段的“调用字段”是“author” #}
<p><strong>作者:</strong> {{ customFields.author.Value }}</p>
{% endif %}
{% if customFields.stock %} {# 假设自定义字段的“调用字段”是“stock” #}
<p><strong>库存:</strong> {{ customFields.stock.Value }}</p>
{% endif %}
{% endarchiveParams %}
{# 方法二:更简洁的方式,直接使用 archiveDetail 标签(推荐已知字段时使用) #}
{# 当您只需要获取一个或少数几个明确知道名称的自定义字段时,archiveDetail 更加直观和简洁 #}
<p><strong>文章作者:</strong> {% archiveDetail with name="author" %}</p>
<p><strong>商品库存:</strong> {% archiveDetail with name="stock" %}</p>
Here we seearchiveDetailTags can also directly retrieve custom fields, for known, specific fields, this is usually the recommended approach as it is more concise in syntax.archiveParamsofsorted=falsemodes andarchiveDetailautoarchiveParamsautoNameandValueautoarchiveDetailautoValue.
autoAssuming you have defined a custom field "Product Image Group" (call field) in the backgroundproduct_images), it allows multiple images to be uploaded.
{% archiveParams params with sorted=false %}
{% if params.product_images and params.product_images.Value %} {# 检查是否存在产品图片组及是否有值 #}
<h3>产品图片展示:</h3>
<div class="product-gallery">
{% set imageUrls = params.product_images.Value %} {# 获取图片URL的字符串,通常为JSON格式或逗号分隔 #}
{% set imageArray = imageUrls | list %} {# 假设后台存储的是JSON格式的字符串数组,这里使用list过滤器将其转换为数组 #}
{% for imgUrl in imageArray %}
<img src="{{ imgUrl }}" alt="产品图片">
{% endfor %}
</div>
{% endif %}
{% endarchiveParams %}
This example demonstratesarchiveParamsThe flexibility in handling complex custom data (such as image arrays), usually requires combining AnQiCMS filters (such aslist) to parse and display.
archiveParamsrelationship with other tags
archiveParamsNot exist in isolation, it is closely connected with the AnQiCMS ecosystem:
- Relationship with the content model (Content Model):
archiveParamsEverything displayed is from the backendContent Modelis defined inCustom fieldsWithout the expansion of content models,archiveParamsthere is nothing to cook. - With
archiveDetailTag relationships:As mentioned earlier,archiveDetailcan be accessed directly throughname="自定义字段名"The way to obtain the value of a single custom field. When you only care about a specific custom field,archiveDetailit is usually more concise.archiveParamsIt is more suitable for scenarios where dynamic traversal of all custom fields is needed, or where fine-grained control over fields is required.NameandValueThe scenario for performing more refined control over objects. - With
archiveFiltersTag relationships:archiveFiltersUsed to generate filtering conditions on list pages, and the underlying data also comes from the 'Filterable Parameters' configured in the content model.archiveParamsIt is for individual documents, displaying their specific parameter values.
Summary
archiveParamsLabels are an indispensable tool for AnQiCMS content operation experts.It provides AnQiCMS with great content customization flexibility, allowing you to easily display the rich custom parameters defined in the background content model in a user-friendly front-end manner.archiveParamsThe use of, can make your AnQiCMS website content more attractive and better meet business needs.
Common Questions (FAQ)
- When should I use
archiveParamsWhen to usearchiveDetailHow to get custom fields?- Use
archiveParams:When you need to traverse and display a documentallorMostWhen customizing fields (especially when you are unsure about the fields, or when fields may change dynamically), or
- Use