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

Calendar 👁️ 59

AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides great freedom in content display.Among them, the custom parameter feature allows website operators to add unique attributes to content models such as articles, products, and others according to their actual business needs, such as product specifications, author information, source channels, etc.archiveParamsLabels, especially their core parameterssortedingenious application.

The flexibility of custom parametersarchiveParamsbridging role

In the AnQiCMS backend, when you create a content model (such as "article" or "productThese custom parameters greatly enrich the expression of content, meeting the personalized needs of different industries.

We need to call and display these custom parameters carefully set in the background on the front-end pagearchiveParamsThe tag acts as a bridge, securely and efficiently passing structured data from the backend to your template for rendering and display.

sortedParameter: the key to controlling the output order

archiveParamsThe core charm of tags lies in itssortedThe parameter determines how the custom parameters you obtain from the background are presented, thereby affecting the way you access and iterate over these parameters in the template. It supportstrueandfalseTwo values, by defaulttrue.

WhensortedWithtrueWhen (the default behavior): the beauty of traversing an ordered array

When you usesorted=true(or not explicitly specifiedsortedbecause the parameter,trueis the default value whenarchiveParamsthe tag will treat the custom parameters of the specified document asan ordered array of objectsand return it to the template. Each element of this array is a container that includesNameandValueThe field object, respectively corresponding to the Chinese name of the custom parameter and its corresponding value.

The advantage of this pattern is that it will output strictly according to the order of the custom fields defined in the background "content model". This means that if you want the order of the custom parameters displayed on the front-end to be consistent with the order set in the background, or if you need to traverse all custom parameters dynamically without concerning about the specific field names, thensorted=trueis your best choice. In the template, you usually combineforloop to traverse these parameters, thus achieving flexible and dynamic display.

For example, if you want to list all the custom properties of the article one by one, you can write the template code like this:

{% archiveParams params %}
<div>
    {% for item in params %}
    <div>
        <span>{{item.Name}}:</span>
        <span>{{item.Value}}</span>
    </div>
    {% endfor %}
</div>

This code will traverseparamsEach custom parameter in the array, and its name (item.Name) and value (item.ValuePrint it out, perfectly following the order defined by the background.

WhensortedWithfalseAt: precise positioning of unordered mapping

withsorted=trueRelatively, when you are going tosortedthe parameter tofalsethen,archiveParamsThe tag will return aUnordered mapping (map) objectIn this mode, you can directly access it by using the 'call field' of custom parametersNameandValue.

sorted=falseThe main advantage lies in its directness and efficiency.When you know exactly which specific custom parameters to display and do not want to perform additional loops, this method is very convenient.It is like a dictionary, you can directly access the corresponding value through the key (i.e., the custom field's 'access field'), without concerning about their arrangement in the background.

For example, if your article model has a field namedauthorThe custom parameter of the (field called), you can directly obtain its value in the following way:

{% archiveParams params with sorted=false %}
<div>作者名称:{{params.author.Value}}</div>
<div>作者标签名:{{params.author.Name}}</div>

Or, if you only want to get the value of a custom field and output it directly, you can also omit the variable name and output it directly inarchiveDetailthe tag throughnameParameter specification, to some extent, also utilizes similarsorted=falsethe direct access thought:

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

Although this direct inarchiveDetailis usednameThe way of using parameters is more concise, butarchiveParams params with sorted=falseProvided aparamsobject that allows you to easily access multiple specified fields within a context, rather than callingarchiveDetail.

how to choose an appropriatesortedvalue?

SelectsortedThe value of the parameter, mainly depends on your content display requirements:

  • Usesorted=true(Default):

    • When you want to display all custom parameters dynamically in an area and maintain their order defined in the background.
    • When you are unsure about which custom parameters will be present, or when the number and type of custom parameters change frequently, using a loop to traverse them can better adapt to this change.
    • For example, display the list of all technical parameters of the product, or all the metadata of the article.
  • Usesorted=false:

    • When you need to accurately retrieve and display one or more known specific custom parameters.
    • When performance is a key consideration, and you only want to access a few specific fields while avoiding unnecessary iteration.
    • For example, directly display the 'author' and 'publish date' below the page title, or show the 'price' at the top of the product details page.

In summary,archiveParamslabel'ssortedThis parameter provides you with the powerful ability to flexibly control the output method of custom parameters.Understand and use it well, it will make your AnQiCMS website content management and front-end display more efficient, accurate, and flexible.


Frequently Asked Questions (FAQ)

  1. Ask: When custom parameters are defined in the background "Content Model", their order affects the front endarchiveParamsDoes the tag output? Answer:Yes, ifarchiveParamsThe tag uses the defaultsorted=truepattern, then pass through the templateforWhen iterating over these parameters, their output order will strictly follow the sequence you define for these custom fields in the AnQiCMS backend "Content Model". If you changesortedis set tofalseSince it is an unordered mapping, the order of access is no longer meaningful, you need to directly obtain it through the 'field calling field'.

  2. Ask: I want to display a specific custom parameter, such as a parameter named "author", usingsorted=trueOrsorted=falsemore efficiently? Answer:In this case, usingsorted=falsewill be more direct and efficient. Becausesorted=falseIt returns a map object, you can directly access it through its 'call field', for example{{params.author.Value}}, without having to traverse the entire parameter list. If you usesorted=trueYou then need to iterate over all parameters and judge inside the loopitem.Namewhether it is "author", which is relatively inefficient.

  3. Question: If I usesorted=falseHow to access a non-existent custom parameter, for example{{params.nonExistentField.Value}}Will the page report an error? Answer:In most cases, AnQiCMS's template engine will not directly throw a fatal error causing the page to crash. It will simply{{params.nonExistentField.Value}}Parsed as an empty string or a null value (depending on the implementation), no content will be displayed on the page.This makes the template have better error tolerance when facing missing fields.{% if params.nonExistentField %}Avoid outputting empty tags or unnecessary structure.

Related articles

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 output system information configured in the AnQiCMS template, such as website name, Logo, and filing number?

In the flexible world of AnQiCMS, elegantly presenting the system-level information configured in the background to the front end of the website is a core skill that every website operator and template developer needs to master.As an experienced website operations expert, I know that these seemingly trivial details are invaluable for enhancing brand image, optimizing user experience, and meeting regulatory requirements (such as displaying the filing number).Today, let's delve deeply into how to output these valuable background information in the AnQiCMS template in a natural and smooth manner. AnQiCMS

2025-11-06

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

As an experienced website operation expert, I know that how to flexibly use template tags to display content in such an efficient content management system as AnQiCMS is the key to operation success.Today, let's delve into how the `archiveParams` tag's `sorted=true` and `sorted=false` parameters can have an effect in specific scenarios.Anqi CMS, with its concise and efficient architecture, provides great convenience for content creators and operators.

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