How to use the `archiveFilters` tag to build a dynamic document filtering feature, such as filtering by product parameters?

Calendar 👁️ 61

Utilizing AnQiCMS'sarchiveFilterstags, building an efficient and practical dynamic filtering function

In the field of content management and e-commerce, it is crucial for users to be able to quickly and accurately find the information they need to improve website experience and conversion rates.Imagine when users browse products or documents on your website, if they can quickly filter out the content they want based on various conditions such as color, size, brand, and even more specific parameters such as processor type and memory size, this will greatly enhance their user experience.Provided by AnQiCMSarchiveFiltersThe label is born for this, it allows you to easily build a powerful, flexible and versatile dynamic filtering interface.

The value of dynamic filtering: why is it indispensable?

The traditional list display method, usually can only be sorted by time, popularity, or category.However, for websites with a large amount of content or various parameter attributes (such as product, service introductions, technical documents, etc.), this method is obviously not sufficient to meet the refined search needs of users.

The core of dynamic filtering function lies in converting various attributes of content into interactive filtering conditions.Users can freely select one or more conditions, the website will update in real-time, and only display documents that meet the conditions.This greatly enhances the discoverability of content, reduces the cost of user search, and also provides data insights for website operators to understand user preferences, thereby optimizing content strategies and product presentations.This is an essential tool for e-commerce websites to enhance customer satisfaction and boost sales.

Lay a foundation: content model and custom fields

Further understandarchiveFiltersBefore the label, we need to understand the source of dynamic filtering. AnQiCMS is powerful due to its 'flexible content model' feature.All filterable parameters must be predefined as 'custom fields' in the 'Content Management' module under the 'Content Model' in the background.

For example, if you need to build a filter function for a product, you may need to create a content model named "Product Model" (AnQiCMS provides it by default), and then add custom fields under this model, such as:

  • Field Name:Color,Call field: color,Field type:Single choice (for example: Red, Blue, Black)
  • Field Name:Size,Call field: size,Field type:Single choice (for example: S, M, L, XL)
  • Field Name:Processor,Call field: processor,Field type:Dropdown selection (for example: Intel i7, AMD Ryzen 7)

These custom fields will become the basis for your front-end dynamic filtering. Make sure that the products or documents you publish have filled in the corresponding values according to these fields.

archiveFiltersThe core function of tags: build filtering conditions

In the template system of AnQiCMS,archiveFiltersThe tag plays the role of a 'director' in generating dynamic filtering conditions.It will automatically retrieve and organize all available filter parameters and their optional values based on the model you specify and the context of the current page.It is noteworthy that,archiveFiltersTags are mainly used on the document home page or document category list page templates and are usually combined with document pagination lists (archiveListLabel collaborationtype="page") for use.

The basic usage of this tag is as follows:

{% archiveFilters filters with moduleId="1" allText="全部" %}
    {# 筛选条件渲染代码 #}
{% endarchiveFilters %}

Here:

  • filtersIt is the custom variable name you create for the filtered results, which will contain all available filter parameter data.
  • moduleIdParameters are crucial, as they specify the filter parameters of the content model you want to retrieve. For example,moduleId="1"indicating the parameters for retrieving the article model,moduleId="2"It may represent the parameters of a product model. You can view the IDs of each model in the background "Content Model".
  • allTextThe parameter is used to set the display text of the "All" option in the filter conditions, if it is set tofalseit will not be displayed.

WhenarchiveFiltersAfter the tag is executed, it will fill the filtered data into the one you definefiltersIn the variable. ThisfiltersVariables are actually an array where each element represents a filterable parameter category (for example, "Color"). Each parameter category also contains aItemsAn array lists all specific filter values under the category (such as "Red", "Blue"), as well as the corresponding links and the current selected status.

Deploy in the template.archiveFilters

Now, we will combine actual code snippets to demonstrate how to deploy in your AnQiCMS templatearchiveFiltersto build dynamic filtering functionality.

First, make sure you have included in the template.archiveFiltersLabel, and witharchiveListUsed together, so that after the user selects the filter conditions, the filtered document list can be displayed in real time.

The following is a typical layout of a filter function:

<div class="filter-area">
    <div class="filter-header">筛选条件:</div>
    {% archiveFilters filters with moduleId="2" allText="不限" %}
        {% for item in filters %} {# 遍历每个可筛选的参数类别,如:颜色、尺寸 #}
        <ul class="filter-group">
            <li class="filter-name">{{ item.Name }}: </li> {# 显示参数名称,如:颜色 #}
            {% for val in item.Items %} {# 遍历当前参数类别下的所有可选值 #}
            <li class="filter-item {% if val.IsCurrent %}active{% endif %}">
                <a href="{{ val.Link }}">{{ val.Label }}</a> {# 链接到对应的筛选结果页 #}
            </li>
            {% endfor %}
        </ul>
        {% endfor %}
    {% endarchiveFilters %}
</div>

<div class="document-list">
    {# 这里是文档列表,它会根据筛选条件自动更新 #}
    {% archiveList archives with moduleId="2" type="page" limit="10" %}
        {% for item in archives %}
        <div class="document-item">
            <h4><a href="{{ item.Link }}">{{ item.Title }}</a></h4>
            <p>{{ item.Description }}</p>
            {# 假设产品有自定义参数 "processor" 和 "memory" #}
            {% archiveParams params with id=item.Id %}
            {% for param in params %}
                {% if param.FieldName == "processor" %}
                <span>处理器: {{ param.Value }}</span>
                {% elseif param.FieldName == "memory" %}
                <span>内存: {{ param.Value }}</span>
                {% endif %}
            {% endfor %}
            {% endarchiveParams %}
        </div>
        {% empty %}
        <p>抱歉,没有找到符合条件的文档。</p>
        {% endfor %}
    {% endarchiveList %}

    {# 分页导航,配合 archiveList 的 type="page" 使用 #}
    {% pagination pages with show="5" %}
        <div class="pagination-nav">
            {% if pages.PrevPage %}<a href="{{ pages.PrevPage.Link }}">上一页</a>{% endif %}
            {% for p in pages.Pages %}
            <a class="{% if p.IsCurrent %}active{% endif %}" href="{{ p.Link }}">{{ p.Name }}</a>
            {% endfor %}
            {% if pages.NextPage %}<a href="{{ pages.NextPage.Link }}">下一页</a>{% endif %}
        </div>
    {% endpagination %}
</div>

In this example,archiveFiltersThe label first generates all available filter parameter groups. Each parameter group (such as "Color") under it has a dynamically generatedLink. When the user clicks on a filter option, AnQiCMS will automatically parse this link and pass it as a URL parameter to the server.

Related articles

How to customize and display a friendly shutdown notice when the website is in a closed state?

In website operation, we sometimes need to temporarily close the website, whether it is for system upgrades, data maintenance, or short-term business adjustments.It is crucial to display a friendly shutdown prompt to visitors in this case.This not only informs users of the website status, avoids unnecessary confusion, but also maintains the brand image and provides clear guidance for search engines.AnQiCMS (AnQiCMS) provides us with a flexible way to customize and display this information.### Enable website shutdown status and set basic prompts First, you need to set the website to shutdown status

2025-11-08

How to perform arithmetic operations such as addition, subtraction, multiplication, and division in the template and display the result?

In AnQiCMS template design, sometimes we need to perform arithmetic operations such as addition, subtraction, multiplication, and division on the numbers displayed on the page to present data more flexibly.Whether it is to calculate the total price of goods, display dynamic percentages, or perform simple processing of certain statistical data, AnQiCMS's template engine provides intuitive and powerful arithmetic calculation capabilities.AnQiCMS's template engine borrows the syntax style similar to Django templates, allowing us to directly output variables in template files (using `{{

2025-11-08

How to remove leading and trailing spaces or specific characters from a string in the template using a filter?

In website content display, we often encounter situations where there are extra spaces, line breaks at the beginning and end of strings, or specific characters need to be deleted.These seemingly minor details can affect the layout and aesthetic of the page, the accuracy of data display, and even have an adverse effect on search engine optimization (SEO).AnQiCMS is a powerful template engine that provides rich filter functions, which can help us easily and elegantly handle these strings, making your content more accurate and professional.AnQiCMS's template syntax is concise and intuitive, it draws on Django

2025-11-08

How to call and display specific content or system configuration information from other sites in a multi-site management mode?

AnQiCMS's powerful multi-site management feature brings great convenience to users with multiple brands or sub-sites.It can not only help you manage different content sites uniformly, but also supports cross-site data sharing and resource integration.When you want to display content from other sites on a site, or call the system configuration information of other sites, AnQiCMS provides a simple and efficient mechanism to achieve this goal.In AnQiCMS, the core of implementing cross-site content or configuration information calls lies in the flexible use of template tags such as `siteId`

2025-11-08

How can you clearly display the user's comment content, username, reply object, and posting time in the comment list?

In website content operation, the comment section is undoubtedly an important manifestation of user interaction and content depth.A well-designed, clear information presentation comment list that can significantly improve the user's browsing experience and effectively stimulate community activity.AnQiCMS's powerful template system provides us with flexible tools, allowing us to easily achieve the organization of comment content, commenters, reply objects, and posting time.### Understanding the Core Elements of Comment Lists To build a visually appealing and practical comment list, we need to ensure that several key pieces of information are presented intuitively

2025-11-08

How to automatically parse URL strings to clickable `<a>` tags in the article body or description?

In daily website content creation and management, we often need to embed some links in the article body or description, such as referencing external resources, pointing to product pages, or other related articles.If these URLs are only displayed in plain text, users will have to manually copy and paste them into the browser, which undoubtedly will greatly reduce their user experience.幸运的是,AnQiCMS 内置了非常实用的功能,可以自动将这些 URL 字符串智能识别并转换为可点击的 `a` 标签,让网站内容更加友好和便捷。This function mainly through

2025-11-08

How to retrieve and display user group details, such as group name, level, and purchase price, for a membership system?

Today in the operation of the website, building an efficient member system is crucial for content monetization, user stickiness cultivation, and community construction.AnQiCMS (AnQiCMS) provides a solid foundation for building such a system with its flexible design and rich features.Among them, the fine management of user groups is the core of the member system's operation, which allows us to provide differentiated service experiences based on the different identities and rights of users.### User Group Management in AnQi CMS: Basics and Value AnQi CMS built-in user group management function

2025-11-08

How to reuse common HTML fragments in a template by using the `include` tag or define reusable code blocks by `macro`?

In the development and maintenance of website templates, we often encounter the need to reuse HTML code snippets or logical structures.If you always copy and paste, it is not only inefficient, but also once you need to modify it, you have to repeat the operation in multiple places, which is very prone to errors.AnQi CMS knows this point, it provides a template engine that adopts Django's syntax, through `include` tags and `macro` macro functions, allowing us to easily achieve code reuse, greatly enhancing the maintainability and development efficiency of templates.### Reuse the public HTML fragment: `include`

2025-11-08