In Anqi CMS, displaying and filtering custom content attributes are the core of implementing flexible and personalized website functions. With the help of template tags in thearchiveParamsandarchiveFiltersWe can easily display custom content fields on the front end and provide users with powerful features for filtering content based on these fields, thus greatly enhancing the user experience and discoverability of the website.

archiveParamsLabel: Flexible display of custom properties

In AnQi 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, and publish time, we can also add custom fields like 'author', 'source', 'price', 'size', etc.These custom fields are the foundation for personalizing website content.

When we need to display these custom properties on a document detail page (such as a product introduction or a professional article),archiveParamsThe tag comes into play. Its main function is to obtain all the custom parameters associated with the current document or a specified document.

UsearchiveParamsVery intuitive. You can place it in the template of the document detail page, and it will automatically obtain the custom parameters of the current page document.If you need to get the parameters for a specific ID document, you can also throughidparameter.

archiveParamsThere are two common ways to access the custom parameters returned by the tag:

  1. As a fixed sorting array (default behavior,sorted=true):When we want to display all custom fields in order, this method is very suitable. The tag will return a list containing the names of each custom field (Name) and value (ValueThe object array. We can iterate through and display all custom parameters in the template, for example:{% for item in params %}Such a loop structure, iterate and display all custom parameters, for example:

    {% 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 details page, no need to preset field names, the system will automatically list all parameters added in the background.

  2. 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 background custom field is set toauthorWe can convertsortedthe parameter tofalseThus,archiveParamsIt will return a Map, we can directly access it through.By adding an operator and the name of the field being called to access its value, for example:

    {% archiveParams params with sorted=false %}
    <p>作者:{{params.author.Value}}</p>
    {% endarchiveParams %}
    

    This method is suitable for scenarios where a single, known custom field needs to be referenced in a template.

Combined with document details tagarchiveDetailWe can even directly call the name of the custom field to get its value, 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.

archiveFiltersLabel: Drives the dynamic filtering of the user experience

When we have a large amount of content and we want users to be able to narrow down the search range based on these custom properties,archiveFiltersTags are particularly important. They are mainly used to generate filtering links based on custom attributes on document list pages or category pages.Imagine a real estate website where users may need to filter listings by custom attributes such as 'house type', 'price range', 'area', etc.archiveFiltersIt is born for this.

this tag needs to be with,archiveList(used to display document lists) andpagination(Used for pagination) Tag used in conjunction to build a functional filter 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 values, each with a URL link for executing the filter, and aIsCurrentStatus, indicates whether the current filter value is selected.

UsearchiveFiltersThe basic process is as follows:

  1. Define filter properties:First, in the Anqi CMS backend's "Content Model", make sure you have defined custom fields that can be used for filtering in your content model (for example:户型/面积)
  2. Use in the template:In the document list page template, usearchiveFilterstags to obtain the filtering condition data. It is usually assigned to a variable, for examplefilters:
    
    {% 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 %}
    
    HeremoduleIdThe parameter is very important, it tells the label which custom filter attribute of the content model should be retrieved.allTextIt is used to set the display text for the 'unlimited' or 'all' options.

when the user clicks{{val.Link}}The page will reload when generating the filter link andarchiveListThe tags will display content that matches the filter parameters carried in the URL.IsCurrentThe attribute helps us add styles (such as highlighting) to the currently selected filter condition, enhancing user experience.

ByarchiveParamsandarchiveFiltersThese 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.


Frequently Asked Questions (FAQ)

Q1: How should I define custom fields so thatarchiveParamsandarchiveFiltersthey can be recognized and used?

A1: You need to find the "Content Model" feature under the "Content Management" module in the Anqi CMS backend.Select the model you want to add a custom field to (for example, 'Article Model' or 'Product Model'), then click Edit.Here, you can add new "custom fields", set the "parameter name" (for background display), "calling field" (for template call), "field type" and other options.Especially, if you want the field to be used for front-end filtering, make sure its data type and settings meet the filtering requirements.

Q2:archiveFiltersCan all types of document fields, including category IDs, tags, etc., be filtered?

A2:archiveFiltersTags are primarily designed to filter the content model you are inCustom attribute fields. For filtering system-built-in fields like category ID (categoryId), recommended attributes(flag), you should directly inarchiveListTag through the corresponding parameters (such ascategoryId="1"/flag="c") to set.archiveFiltersThe advantage lies in its ability to dynamically generate filter options and links for your custom fields, allowing users to filter these specific custom properties through interface interaction.

Q3: If my custom field has no value,archiveParamsHow will 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 use the template toifdetermine whether to display. If it passessorted=falsedirect access,params.yourFieldName.Valuewill also be an empty value.
  • archiveFiltersIt is usually not recommended to display custom fields without values as filter criteria. If all documents for a custom field are not filled in, or if optional values are not set, thenarchiveFiltersLabels may not generate a filter group for this field. If set,allTextThe parameter will display the option of "All" or "Unlimited", but if there are no other specific filter values, the filtering of this field may not have any actual significance.