How to implement complex parameter filtering conditions for the dynamic display of the `archiveFilters` tag on the front end?

Calendar 👁️ 80

In website content operation, providing users with flexible and efficient filtering functions is an important link to improve user experience and help users quickly locate the information they need. AnQiCMS (AnQiCMS) understands this point, especially through its powerful template tag system, especiallyarchiveFiltersTags make it easy for the front-end to dynamically display complex parameter filtering conditions.

Core Functionality and Implementation Principles

archiveFiltersThe core function of the label is to automatically generate frontend filtering conditions and corresponding dynamic links based on the custom fields of the content model. When the user clicks on a filtering condition, the page URL will automatically add the corresponding parameters, the background'sarchiveListTags will dynamically adjust the display content of the document list based on these URL parameters, thereby achieving precise filtering.This process does not require manual writing of complex backend logic, greatly simplifying development and maintenance work.

Preparation: Set up the filtering foundation

To usearchiveFiltersLabels, first you need to do some preparation in the Anqi CMS background:

  1. Custom content model fields:archiveFiltersLabels depend on the custom fields predefined in the content model. Only those set to the types of "single-choice", "multiple-choice", or "dropdown" can bearchiveFiltersLabel recognition and generate filtering conditions.

    • For example, if you are building a real estate website, you can create a content model named "Real Estate Model". In this model, you can add the following custom fields:
      • “House Type” (Single choice, options include “Residential”, “Commercial”, “Office Building”)
      • “Type of apartment”
      • “Degree of decoration” (drop-down selection, options include “raw”, “simple decoration”, “finishing”) The default values filled in these fields in the background will become the “options” of the front-end filtering conditions.
  2. Specific label application scenario:archiveFiltersLabels are mainly designed for the homepage of documents or template pages for document categories, and they are usually associated with document pagination lists (i.e.archiveListlabel'stype="page"Combine the pattern ()} to ensure that the pagination of the filtering results is correct.

archiveFiltersIn-depth analysis of tag usage

archiveFiltersThe basic usage of tags is as follows:

{% archiveFilters filters with moduleId="..." allText="..." %}
    {# 循环输出筛选组 #}
    {% for item in filters %}
        <ul>
            <li>{{item.Name}}: </li> {# 筛选组名称,如“房屋类型” #}
            {% for val in item.Items %} {# 循环输出每个筛选选项 #}
            <li class="{% if val.IsCurrent %}active{% endif %}">
                <a href="{{val.Link}}">{{val.Label}}</a>
            </li>
            {% endfor %}
        </ul>
    {% endfor %}
{% endarchiveFilters %}

Let's break down the parameters and variables returned by this tag in detail:

  • moduleIdParameter: This isarchiveFiltersA very important parameter in the tag. It is used to specify the filtering conditions for which content model to retrieve. For example, if you want to filter documents of the "article model",moduleIdis usually set to1If filtered by "Product Model",moduleIdmay be set to2. This ID can be viewed in the "Content Model" management interface on the backend. By specifyingmoduleIdThe system can accurately retrieve the filtering fields defined under the corresponding model.

  • allTextParameterThis parameter is used to set the display text of the "All" option in the filtering conditions. For example,allText="不限"It will display the word "Unlimited". If you do not want to display the option "All", you can set it tofalsesuch asallText=false.

  • filtersVariable:archiveFiltersThe tag will organize the generated filter conditions into a namedfiltersAn array object (of course, you can customize other variable names). ThisfiltersEach element of the array represents a filter condition group, for example, 'House Type' is a group, and 'House Structure' is another group. Each group object contains the following key attributes:

    • item.NameThis is the display name of the filter group, such as 'House Type', 'Room Layout', etc., which is usually displayed directly on the front-end interface.
    • item.FieldNameThis is the field name used in the URL parameters of the filter group, automatically generated by the system for identifying specific filtering conditions.
    • item.ItemsThis is an inner array that contains all available filter options under the current filter group.
  • valVariable (initem.Itemsin the loop):item.ItemsEach element in the array is a filter option object that contains the following key attributes:

    • val.Label: This is the display text of the filter option, such as 'Residential', 'One-bedroom', etc.
    • val.Link:This is the core of implementing dynamic filtering.val.LinkIs a pre-built URL, when the user clicks on this link, the page will automatically jump and carry the corresponding filtering parameters. For example, clicking on "Residential" may jump to.../list?houseType=住宅.
    • val.IsCurrent: This is a boolean value indicating whether the current filter option has been selected. You can use this property to add CSS styles to the currently selected option (such asactiveClasses), thus highlighting on the front end to improve user experience.

Collaborative work:archiveListwithpagination

archiveFiltersThe tag itself is only responsible for generating links for filter conditions, and the actual data filtering is done byarchiveListComplete with tags. When the user clicksarchiveFiltersAfter generating the link, the URL will contain the corresponding filter parameters. At this point, the page onarchiveListTag (set as)type="page"The pattern will automatically recognize these URL parameters and request data from the backend that meets the filtering conditions.

At the same time,paginationThe pagination label will also intelligently generate the correct pagination link based on the current filter state, ensuring that users can navigate normally within the filtered results.

Practical example: Build a property filter

Assuming you have already defined custom fields such as "house type" and "house style" for the "real estate model" as mentioned earlier, now we can implement a dynamic filter in the front-end template:

`twig {# Assume this is a real estate list page, moduleId="1" is the ID of the real estate model #}

<h2>房产筛选</h2>
{% archiveFilters filters with moduleId="1" allText="不限" %}
    {% for item in filters %}
    <div class="filter-group">
        <span class="filter-name">{{item.Name}}: </span>
        <ul class="filter-options">
            {% 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 %}

{# Document list code: it will automatically load based on the URL filter parameters #}

{% archiveList archives with moduleId=“1” type=“page” limit=“10” %}

{% for item in archives %}
<div class="property-item">
    <a href="{{item.Link}}">
        <img src="{{item.Thumb}}" alt="{{item.Title}}">
        <h3>{{item.Title}}</h3>
        <p>{{item.Description}}</p>
        {# 显示自定义字段,例如“房屋类型”和“户型” #}
        {% archiveParams params with id=item.Id %}
            {% for param in params %}
                {% if param.FieldName == "houseType" %}
                    <span>类型: {{param.Value}}</span>
                {% elseif param.FieldName == "houseLayout" %}
                    <span>户型: {{param.Value}}</span>
                {% endif %}
            {% endfor %}
        {% endarchiveParams %}
        <span>阅读量: {{item.Views}}</span>
    </a>
</div>
{% empty %}
<p>没有找到符合条件的房产信息。</p>
{% endfor %}

{% endarchiveList %}

{# Pagination code: it will automatically adjust the pagination links based on the filtering results #}

{% pagination pages with show="5" %}
    {# 首页 #}
    <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">首页</a>
    {# 上

Related articles

How to implement the sorting display of article list by views (views desc) in AnQi CMS?

How to make a hot article on the website stand out quickly and attract more visitors' attention?This can effectively enhance user experience and is also the key to optimizing content strategy and guiding traffic.For users of AnQiCMS, it is a very practical and easy-to-operate feature to display article lists sorted by page views.The powerful template tag system of AnQi CMS allows you to easily display the most popular content on your website to users.### Core Feature Revelation: Utilize `archiveList`

2025-11-09

How to display the language switch options and hreflang tags on Anqi CMS?

Today, providing multilingual support for websites has become a basic requirement for expanding the market and serving users in different regions.AnQiCMS (AnQiCMS) is fully aware of this need, integrating powerful multilingual functionality to allow website administrators to easily achieve content internationalization.This article will discuss in detail how to effectively display language switch options on AnQiCMS sites and correctly set the `hreflang` tag to optimize the internationalization recognition of search engines.Understanding AnQiCMS' multilingual capabilities AnQiCMS is an efficient

2025-11-09

How does the `breadcrumb` tag in AnQi CMS generate and display flexible breadcrumb navigation?

When building a website, a clear and intuitive navigation system is crucial for user experience and search engine optimization (SEO).Breadcrumb navigation is a tool that can significantly improve website usability, clearly showing the user's current position on the site and providing convenient links to return to the previous level page.AnQi CMS knows this and provides a powerful and flexible `breadcrumb` tag.###

2025-11-09

How to define and display temporary variables in Anqi CMS template for complex content layout?

In website content operation, we often encounter some scenes where we need to flexibly display data and dynamically adjust the layout.Sometimes listing information simply is not sufficient to meet complex design requirements, and at this point, if you can freely define and use some temporary variables in the template, it will greatly enhance our efficiency and the expressiveness of the template.AnQiCMS (AnQiCMS) with its powerful backend developed based on the Go language and the template engine syntax similar to Django, provides us with a flexible mechanism for defining and managing temporary variables, making it possible to create exquisite and complex content layouts.Define a temporary variable

2025-11-09

How to call the backend custom Json-LD structured data in AnQi CMS template and display it?

Today with the rich content on websites, how to make search engines accurately understand web content and display it in a more user-friendly manner has become a key link in website operation.Structured data (usually in Json-LD format) is an important tool to achieve this goal.By embedding Json-LD code in the page, we can provide standardized information for search engines about various content such as articles, products, and reviews, thereby having the opportunity to obtain richer search result displays, which is what we commonly refer to as 'rich snippets' or 'rich results'

2025-11-09

How does Anqi CMS handle and display external links in content, such as adding the `rel="nofollow"` attribute?

In website operation, the management of external links is an indispensable part of content strategy and search engine optimization (SEO).Especially properties like `rel="nofollow"`, which tell search engines not to pass link weight to the linked page, are crucial for managing the link health of a website and avoiding potential SEO risks.AnQiCMS (AnQiCMS) provides multiple ways to handle and display external links in content, including automatically adding the `rel="nofollow"` attribute

2025-11-09

How to correctly display and load images on the front-end page after the website enables Webp image format?

In website operation, the speed of image loading is crucial for user experience and Search Engine Optimization (SEO).WebP is a modern image format that, with its excellent compression performance, significantly reduces file size while maintaining image quality, thus greatly enhancing website loading speed.AnQiCMS (AnQiCMS) fully understands this and has built-in support for WebP image format in its system, making it easy for users to turn it on and benefit from it.However, after enabling the WebP feature, many users may be confused: how can the front-end page correctly display and load these WebP images

2025-11-09

What basic conventions should the template files of Anqi CMS follow to correctly display the content structure?

In Anqi CMS, template files are the basis for presenting website content.It is not just a simple HTML file, but a set of blueprints that follow specific conventions and rules. Only by accurately adhering to these conventions can the system correctly parse, render, and display the structure of your website content.Understanding these basic conventions can help you customize and manage your website more efficiently, ensuring that content is presented in the way you expect to visitors.### The storage location and basic format of the template file Firstly, Anqi CMS has clear requirements for the storage location of template files

2025-11-09