In the AnQi CMS, the display and filtering of custom content attributes are at the core of implementing flexible and personalized website functions. With the help of template tags,archiveParamsandarchiveFiltersWe can easily display custom content fields on the front end and provide users with powerful functionality to filter content based on these fields, thus greatly enhancing the user experience and discoverability of the website.
archiveParamsLabel: Flexible Display of Custom Attributes
In the Auto CMS, we first define unique fields for different types of content (such as articles, products) through the "Content Model" feature.In addition to system built-in fields such as title, content, publish time, etc., we can also add custom fields such as 'author', 'source', 'price', 'size', etc.These custom fields are the foundation for personalizing website content.
When we need to display these custom attributes on the document detail page (such as a product introduction or a professional article),archiveParamsThe label comes in handy. Its main function is to retrieve all custom parameters associated with the current document or a specified document.
UsearchiveParamsvery intuitive.You can place it in the template of the document details page, and it will automatically retrieve the custom parameters of the current page document.idParameters can be specified.
archiveParamsThere are two common ways to access the custom parameters returned by the label:
As a fixed-order array (default behavior,
sorted=true):When we want to display all custom fields in order, this method is very suitable. Tags will return a list containing the names of each custom field (Name) and their values (Value)的对象数组。我们可以在模板中通过{% for item in params %}这样的循环结构,遍历并展示所有自定义参数,例如:{% archiveParams params %} <div> {% for item in params %} <p>{{item.Name}}:{{item.Value}}</p> {% endfor %} </div> {% endarchiveParams %}This is especially convenient when displaying all specifications on the product detail page, no need to preset field names, the system will automatically list all parameters added to the backend.
As an unordered Map object (
sorted=false):If we only want to accurately obtain the value of a specific custom field and know its field name (for example, the "call field" of the custom field in the background is set toauthor),we can translate it into English as,sortedparameter settingsfalselike this,archiveParamswill return a Map, we can directly access it through.the operator combined with the field name to access its value, for example:{% archiveParams params with sorted=false %} <p>作者:{{params.author.Value}}</p> {% endarchiveParams %}This method is suitable for scenarios where you need to reference a single, known custom field in a template.
Combined with document detail tagsarchiveDetailWe can even directly retrieve the value by calling the custom field name, for example{% archiveDetail with name="author" %}This provides great flexibility for template developers, allowing them to choose the most suitable display method based on actual needs.
archiveFiltersTag: Dynamic filtering user experience driven by tags
When we have a large amount of content, and we want users to be able to narrow down the search scope based on these custom properties,archiveFiltersThe label is particularly important.It is mainly used on document list pages or category pages to generate links for filtering conditions based on custom properties.Imagine a real estate website where users may need to filter properties by custom attributes such as 'house type', 'price range', 'area', etc.archiveFiltersThat's exactly why it was created.
This tag needs to be associated witharchiveList(Used to display the document list) andpaginationTags for (Used for pagination) used together, jointly constructing a functional and comprehensive filtering and list display page.
archiveFiltersThe tag will return an array containing multiple groups of filtering conditions, each corresponding to a custom attribute. Each filtering condition group contains a series of selectable filtering values, each with a URL link used for executing the filter.IsCurrentStatus, indicating whether the current filter value is selected or not.
UsearchiveFiltersThe basic process is as follows:
- Define the filter attribute:Firstly, in the "Content Model" section of the Anqi CMS backend, make sure you have defined custom fields that can be used for filtering in your content model (for example:
户型/面积). - Use in the template:In the document list page template, use
archiveFilterstags to get the filtering condition data. The result is usually assigned to a variable, such asfilters:
Here are the{% archiveFilters filters with moduleId="1" allText="不限" %} {% for item in filters %} <div class="filter-group"> <span>{{item.Name}}:</span> {# 筛选属性的名称,如“户型” #} <ul> {% for val in item.Items %} <li class="{% if val.IsCurrent %}active{% endif %}"> <a href="{{val.Link}}">{{val.Label}}</a> {# 筛选值的显示文本和筛选链接 #} </li> {% endfor %} </ul> </div> {% endfor %} {% endarchiveFilters %}moduleIdThe parameter is very important, it tells the tag which custom filter attribute of the content model it should retrieve.allTextIt is used to set the display text for the 'No limit' or 'All' option.
When the user clicks{{val.Link}}Generated filter link, the page will reload, andarchiveListTags will display content that matches the filter parameters carried in the URL.IsCurrentThe property helps us add styles (such as highlighting) to the currently selected filter condition, enhancing the user experience.
PassarchiveParamsandarchiveFiltersThese tags, Anqi CMS provides high flexibility for website operators, whether it is to display the rich details of a single content or to provide users with multi-dimensional content filtering, it can be easily realized, making content management and user interaction more efficient and personalized.
Common Questions (FAQ)
Q1: How should I define custom fields so thatarchiveParamsandarchiveFiltersidentify and use them?
A1: You need to find the 'Content Model' feature under the 'Content Management' module in the Anqi CMS backend.Select the model (e.g., "article model" or "product model") you want to add a custom field to, and then click edit.Here, you can add new "custom fields", set "parameter names" (for backend display), "call fields" (for template calls), "field types", and other options.Especially, if you want this field to be used for front-end filtering, make sure its data type and settings meet the filtering requirements.
Q2:archiveFiltersIs it possible to filter all types of document fields, including category ID, tags, etc?
A2:archiveFiltersLabels are primarily designed to filter what you select in the "Content Model".Custom attribute fields.. For filtering built-in system fields such as Category ID (categoryId), recommended attributes (flag), you should directly inarchiveListLabels are set through corresponding parameters (for examplecategoryId="1"/flag="c").archiveFiltersThe advantage lies in its ability to dynamically generate the filtering options and links for the custom fields you define, allowing users to interact with the interface to filter these specific custom attributes.
Q3: If my custom field has no value,archiveParamshow should it be handled?archiveFiltershow will it behave?
A3: If a custom field is not filled in the document:
archiveParamsthe field will beValueMay be an empty string ornilYou can determine whether to display it through the template.ifjudgment.sorted=falseIf accessed directly,params.yourFieldName.Valueit will also be an empty value.archiveFiltersThe custom field without a value is usually not displayed as a filter condition. If all documents of a custom field do not have a value filled in, or if no optional values are set,archiveFiltersLabel may not generate a filter group for this field. If setallText参数,它会显示“全部”或“不限”选项,但如果没有其他具体的筛选值,该字段的筛选可能就没有实际意义。