In the `archiveParams` tag, what scenarios are `sorted=true` and `sorted=false` applicable to?

Calendar 👁️ 58

As an experienced website operation expert, I am well aware that how to flexibly use template tags to display content in a high-efficiency content management system like AnQiCMS is the key to operational success. Today, let's delve into it in detail.archiveParamsTagged,sorted=trueandsorted=falseThese parameters can play a role in specific scenarios.

The Anqi CMS offers great convenience to content creators and operators with its simple and efficient architecture.Among them, the custom content model function is particularly powerful, allowing us to add various additional fields to content types such as articles, products, etc. to achieve personalized content display. AndarchiveParamsThe tag is the core tool from which we obtain data from these custom fields and flexibly present it in the front-end template.

archiveParams: Unlock personalized data of the document

archiveParamsThe purpose of the label is very clear: it helps us obtain all the custom parameters set for a specific document in the Anqie CMS backend (whether it is an article or a product).These parameters may include product features, author information, publishing platform, estimated reading time, etc., which greatly enrich the dimensions of the content.

The basic usage of this tag is usually{% archiveParams params with id="1" sorted=true %}. Among them,idThe parameter specifies which document's custom parameter to retrieve (if not specified, it defaults to the document on the current page). AndsortedParameters, which are the focus of our discussion today, determine how these custom parameters are extracted and used in what structure.

sorted=trueWhen the order of fields is crucial for general display:

Whensortedthe parameter totrueat this time (which is alsoarchiveParamsThe default behavior will return aThe array objects are arranged in order defined by the backgroundEach element of this array is a container that includesName(field name) andValue(field value) object.

Application scenarios:

Imagine that you are designing a product detail page template, and you need to display a "Product Specifications" or "Additional Information" block at the bottom of the page. In this block, you want to list all custom parameters in order according to the fields defined in the backend, for example:

  • Processor: Intel Core i7
  • Memory: 16GB DDR4
  • Storage: 512GB SSD
  • Color: Dark Grey

In this case, the order of the fields is usually important, and you may want this block to be able to adapt to new parameters added in the future without modifying the template code.

sorted=trueAdvantages:

  1. Strong in versatility:The template does not need to know the specific field names, it only needs to iterate through the array to display all parameters. This is very convenient for creating universal components such as product parameter lists and article metadata lists.
  2. Low maintenance cost:The backend can add, delete, and modify custom fields, and the front-end template usually does not require any changes because it is dynamically traversed.
  3. Maintain order:Sort strictly according to the custom field sorting on the backend, ensuring the logical and consistent presentation of content.

Code example:

{# 假设我们正在一个文档详情页,需要显示所有自定义参数 #}
<h3>产品规格:</h3>
<ul>
    {% archiveParams productSpecs with sorted=true %}
    {% for item in productSpecs %}
    <li>
        <strong>{{ item.Name }}:</strong>
        <span>{{ item.Value }}</span>
    </li>
    {% endfor %}
    {% endarchiveParams %}
</ul>

This code will dynamically traverse and display all custom parameters, which is very suitable for building universal and expandable specifications or additional information modules.

sorted=false: Accurately locate specific data, flexible layout

Whensortedthe parameter tofalsethen,archiveParamsWill return oneAn unordered Map (or object). In this Map, each custom field's 'display field name' (which is the English identifier set during back-end definition, such asauthor,price,skuetc.") will be used as the key of the Map, while the corresponding field values and metadata (such asNameandValue) will be its value. We can directly access these named parameters through the dot (.) syntax.

Application scenarios:

Suppose you need to display the author's name prominently below the article title, or highlight the price and stock status at a specific location on a product page. These scenarios usually require you to accurately obtain a certainknown and specificThe value of the custom field, and embed it into the specific position of the page layout, rather than listing uniformly.

  • Article page:Display "Author: [Custom field 'author']" at the top of the article
  • Product page: Display 'Price: [Custom field 'price']' and 'Stock: [Custom field 'stock']' next to the purchase button
  • SEO optimization:Access a specific custom field as<meta>the content of the tag.

sorted=falseAdvantages:

  1. Accurate access:You can directly access a specific parameter through the field name 'call field name', without traversing.
  2. Flexible layout:Can accurately place specific data at any position in the template, seamlessly integrating with the overall design.
  3. Conditional judgment:Convenient for conditional judgment of specific field values, such as 'If the price is empty, display Negotiable.'

Code example:

{# 假设我们需要在文章标题下方显示作者和阅读时间估算 #}
<div class="article-header">
    <h1>{{ archive.Title }}</h1>
    {% archiveParams postMeta with sorted=false %}
    <p class="meta-info">
        {% if postMeta.author.Value %}
            作者:{{ postMeta.author.Value }}
        {% endif %}
        {% if postMeta.read_time.Value %}
            · 阅读时长:{{ postMeta.read_time.Value }} 分钟
        {% endif %}
    </p>
    {% endarchiveParams %}
</div>

{# 访问特定字段的Name和Value #}
<p>
    字段名:{{ postMeta.author.Name }},字段值:{{ postMeta.author.Value }}
</p>

Here, we directly go throughpostMeta.author.ValueTo obtain the author name, which makes the template code more targeted.

How to choose a strategy suitable for you?

Selectsorted=trueOrsorted=falseIt mainly depends on how you want to process and display these custom data in the template:

  • When you need to dynamically display all custom parameters and pay attention to their arrangement in the background, please usesorted=true.This is suitable for creating a general information display area, such as product specifications tables, detailed parameter lists of articles, etc.
  • When you need to accurately obtain one to several known custom parameters, and embed them into specific positions in the template, or need to make conditional judgments based on the values of these parameters, please usesorted=false.This is suitable for displaying specific information at key positions on the page (such as next to the title or price area)

In fact, within the same template, you can flexibly combine these two methods according to the needs of different regions. For example, in the main information area of the product details page, you can usesorted=falseTo display prices, models, and other core parameters, while in the "More Parameters" section at the footer, it usessorted=trueList all the additional specifications. This combination application can make your security CMS website present content both universally and uniquely.

Summary

Of Security CMSarchiveParamstags and theirsortedParameters provide website operators with great flexibility to adapt to diverse content display needs. Understand and apply appropriatelysorted=trueandsorted=falseCan help us manage and optimize website content more efficiently, enhance user experience, and ultimately help achieve content marketing goals.


Frequently Asked Questions (FAQ)

Q1: Can I use the same template simultaneously?sorted=trueandsorted=falseGet custom parameters?

A1:Of course. The Anqí CMS template engine design allows you to use different template engines in different areas of the same template file according to different display needssorted=trueandsorted=falseFor example, you can use it at the top of the pagesorted=falseto display several important, named custom fields (such as author, price), while using a general 'parameter list' area on the pagesorted=trueDynamically display all additional fields. This combination can maximize the flexibility of content presentation.

Q2: If I usesorted=trueTraverse the parameters, but how to skip some specific custom fields?

A2:When you usesorted=trueAfter obtaining the custom parameter array, you canforcombine condition judgment within the loop (iftag) to skip specific fields. Each array element includesitem.Name(field display name) anditem.FieldName(Field name used). You can judge based on these two properties. For example, if you do not want to display the field name used asinternal_notesyou can write the parameter as:

{% archiveParams productSpecs with sorted=true %}
    {% for item in productSpecs %}
        {% if item.FieldName != 'internal_notes' %}
            <li><strong>{{ item.Name }}:</strong><span>{{ item.Value }}</span></li>
        {% endif %}
    {% endfor %}
{% endarchiveParams %}

Q3: How do custom field data types manifest in the template? For example, numbers, text, or checkboxes.

A3:InarchiveParamsThe custom parameters obtained from the tag,ValueThe field will be treated as a string type (or any type that can be converted to a string) unless the template engine itself performs special parsing. If you have defined checkboxes or radio buttons in the background,ValueIt usually contains a string of options selected by the user (possibly separated by commas). For more complex data types (such as multiple image URLs), you may need to according toValueThe content is to be further parsed or processed in the template. For example, ifValueIs a JSON string containing multiple image URLs, you may need to use a filter or custom logic to convert it to an array before iterating over it.Generally, AnQi CMS strives to provide complex data in a string format that is easy to parse.

Related articles

In AnQiCMS, how does the `sorted` parameter of the `archiveParams` tag control the output order of custom parameters?

AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides great freedom in content display.Among them, the custom parameter function allows website operators to add unique attributes to content models such as articles, products, etc. according to their actual business needs, such as product specifications, author information, source channels, etc.How to elegantly display these custom parameters in the front-end template, especially the clever use of the core parameter `sorted`, is indispensable.

2025-11-06

How is the `archiveParams` tag's `id` parameter used to retrieve custom fields of a specific document?

As an experienced website operation expert, I am happy to give you a detailed explanation of how the `archiveParams` tag's `id` parameter is used to obtain custom fields of specific documents in AnQi CMS.The AnQi CMS, with its flexible content model and powerful template tag system, provides great convenience for content operations.Grasp the essence of these tags, which can make your website content display more personalized and greatly increase operational efficiency.

2025-11-06

How to use the `archiveParams` tag to display all custom parameters of the current document in AnQiCMS template?

AnQiCMS template's `archiveParams` tag: easily display all custom parameters of the document As a senior website operations expert, I am well aware that in a content management system, how to flexibly display and utilize the various properties of documents is crucial for website customization and functional expansion. AnQiCMS, as an efficient and customizable content management system, provides a rich and powerful set of template tags, among which the `archiveParams` tag is the core tool to unlock the powerful features of document custom parameters.

2025-11-06

What is the core function of the `archiveParams` tag in AnQiCMS template?

In the world of AnQi CMS templates, 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.Today, let's delve deeply into a crucial tag in the AnQiCMS template, `archiveParams`, which is the幕后 hero behind highly customized content.What is the core function of the `archiveParams` tag in AnQiCMS templates?

2025-11-06

How to loop through and display the `Name` and `Value` of custom parameters using the `archiveParams` tag in AnQiCMS templates?

In the flexible world of AnQiCMS, the custom parameters (Content Model) provide website operators with great freedom, allowing us to break through the limitations of traditional titles, content, and summaries, and add personalized data fields for different types of documents (such as articles, products, cases, etc.). For example, a product detail page may need to display information such as 'product model', 'color options', 'material', etc., while a technical article may require fields such as 'author', 'publication date', 'references', etc.

2025-11-06

How to use the `archiveParams` tag to dynamically display the product specification parameter list on the product detail page?

In the era where content is king, an efficient and flexible content management system is crucial for a company's online operations.AnQiCMS (AnQiCMS) is an advanced enterprise-level content management system developed based on the Go programming language, with its powerful content model and template tag system, providing us with infinite possibilities for refined content operation.Today, let's delve into a very practical scenario: how to cleverly use the AnQiCMS `archiveParams` tag to dynamically display a rich variety of product specification parameter lists on the product detail page

2025-11-06

How to call the `archiveParams` tag individually in AnQiCMS template to get custom document parameters with a specific name?

In the rich feature treasure trove of AnQiCMS, the content model and custom document parameters are undoubtedly the foundation of its flexibility and powerful extensibility.As an expert in website operations, I am well aware of how to efficiently and accurately call these custom parameters in templates, which is crucial for achieving personalized content display and optimizing operational efficiency.Today, let's delve deeply into a powerful and often overlooked technique in the AnQiCMS template: how to call the `archiveParams` tag individually to obtain custom document parameters with a specific name.Introduction

2025-11-06

How to implement cross-site calls for the `siteId` parameter of the `archiveParams` tag in the AnQiCMS multi-site environment?

## Mastering AnQi CMS Multi-Site: Cross-Site Call Practice of `archiveParams` Tag SiteId Parameter As an experienced website operations expert, I fully understand that efficient content management and flexible content scheduling are the keys to business success in increasingly complex network environments.AnQiCMS (AnQiCMS) provides powerful tools for operators with its excellent multi-site management capabilities.Today, let's delve into a very practical feature in a multi-site environment

2025-11-06