How to use the `IsCurrent` property to mark the currently selected filter condition in the `archiveFilters` filter tag?

Calendar 👁️ 57

As an experienced website operations expert, I know that user experience (UX) plays a key role in the success of a website.A user-friendly and responsive interface can effectively guide users to discover content, and the content filtering function is an important part of improving user experience.In the AnQiCMS (AnQiCMS) this efficient and customizable content management system,archiveFiltersTags provide strong support for building flexible filtering functions, while its internalIsCurrentproperties are the 'magic wand' that lights up the user experience.

Today, let's delve into it deeplyarchiveFiltersHow to cleverly utilize filtering tagsIsCurrentProperties to mark the currently selected filtering conditions, making your website's content filtering feature both powerful and user-friendly.

The core feature revelation:archiveFiltersWith content filtering

In AnQiCMS,archiveFiltersTags are a very practical tool that allows us to dynamically generate a list of filtering conditions based on various custom parameters of the website content.Imagine that your website has published a large number of products or articles, and users may need to search based on various dimensions such as "color", "size", "release date", or "product type".Manually building these filters is not only time-consuming but also difficult to maintain.archiveFiltersIt was born to solve this pain point.

The principle of its operation is: you define various custom fields for content models (such as "product" or "article") in the background, and may set optional values for these fields.archiveFiltersThe label can intelligently read these configurations and automatically generate filter options available for users to select on the front-end.

For example, if you are running a real estate information website, you can set custom parameters for the '房源' model such as 'house type' (such as residential, commercial) and 'house type' (such as one-bedroom, two-bedroom) and so on.archiveFiltersTags can dynamically render corresponding filter options based on these parameters.When the user clicks on an option, it will generate the corresponding URL link and load the content list that meets the conditions.

archiveFiltersThe usage of tags is usually like this:{% archiveFilters filters with moduleId="1" allText="全部" %}...{% endarchiveFilters %}

here,filtersis an array object that contains all the parameter groups available for filtering. Each parameter group also contains specific filtering options. It is one of these key properties of the filtering options thatIsCurrentGave life to the filtering function.

The touch of genius:IsCurrentThe magic of properties

InarchiveFiltersEach independent filtering value generated by the tag:val) has aIsCurrentBoolean attribute. This attribute is very intuitive:

  • When a filter condition is selected by the user and activated, its correspondingval.IsCurrentthe value will betrue.
  • On the contrary, if the condition is not selected,val.IsCurrentthenfalse.

Why thisIsCurrentThe attribute is so important?

My experience tells me that what users need most when interacting with the interface is clear feedback.When they click a filter option and there is no visual change, they may feel confused, unsure whether the operation was successful, or what the current filter state is.IsCurrentThe attribute precisely solves this problem:

  1. Immediate visual feedback:We can make use ofIsCurrentThe attribute adds a specific CSS class for the currently selected filter condition, for exampleactive. The selected condition will be highlighted, or the background color, font style, etc. will be changed, so that the user can identify the current filter of the application at a glance.
  2. Improve user experience:A clear selected state can effectively reduce the user's cognitive burden and improve their confidence and satisfaction with website operations.They can easily manage their own filtering conditions without getting lost in complex options.
  3. Auxiliary interaction design:When designing the filter area,IsCurrentCan guide us on how to display the filter status more elegantly. For example, set the default highlight for the 'All' option, or in the multi-select mode, keep all selected conditions highlighted.

IsCurrentDirectly map the logical state of the backend to the frontend visual representation, achieving seamless connection between technology and user experience.

Practical exercise: Applying in AnQiCMS templateIsCurrent

UnderstoodIsCurrentThe importance, let's see how to actually use it in the AnQiCMS template. Suppose we have a list page of articles, which needs to be based on the custom field "article type" (articleTypeFiltering out:

{# 页面加载时,使用 archiveFilters 标签获取筛选器数据 #}
{% archiveFilters filters with moduleId="1" allText="不限" %}
    <div class="filter-group">
        {# 循环遍历每一个筛选参数组,例如“文章类型”、“发布年份”等 #}
        {% for item in filters %}
            <ul class="filter-items">
                <li><span class="filter-name">{{ item.Name }}:</span></li>
                {# 循环遍历当前参数组下的所有可选筛选值 #}
                {% for val in item.Items %}
                    {# 利用 IsCurrent 属性判断当前筛选值是否被选中 #}
                    <li class="filter-option {% if val.IsCurrent %}is-active{% endif %}">
                        {# val.Link 提供了点击此筛选项后跳转的 URL #}
                        <a href="{{ val.Link }}">{{ val.Label }}</a>
                    </li>
                {% endfor %}
            </ul>
        {% endfor %}
    </div>
{% endarchiveFilters %}

{# 在此下方,您可以放置 archiveList 标签来显示根据筛选条件过滤后的文章列表 #}
{# 例如:
{% archiveList archives with moduleId="1" type="page" limit="10" %}
    {% for article in archives %}
        <div class="article-item">
            <h3><a href="{{ article.Link }}">{{ article.Title }}</a></h3>
            <p>{{ article.Description }}</p>
        </div>
    {% endfor %}
    {% pagination pages with show="5" %}
        {# 分页链接,同样会根据当前的筛选条件生成 #}
        {# ... #}
    {% endpagination %}
{% endarchiveList %}
#}

In the above code, when the user clicks on the 'Article Type' option under 'News', if 'News' is the current selected condition, AnQiCMS willval.IsCurrentis set totrue. At this point,{% if val.IsCurrent %}The condition is met,is-activethe class will be added to the corresponding<li>tag. You just need to define the style in CSS.filter-option.is-activeto highlight the "News" option, providing clear visual guidance to the user.

Content strategy for content operation

IsCurrentThe application of properties is not only the realization of front-end technology, but also the embodiment of content operation strategy.

  • Optimize user path:Through clear filtering feedback, users can browse and discover content more smoothly on your website, reducing bounce rates and extending stay time.
  • A/B testing opportunity:We can try differentis-activestyles, find the design that best attracts user attention and improves click-through rate through A/B testing.
  • Personalized experience:Combine AnQiCMS's flexible content model, you can design unique selected states for different types of filters, further enhancing the professionalism and personalization of the website.

AnQiCMS'archiveFilterswith the tag andIsCurrentThe combination of properties undoubtedly provides a powerful and flexible tool for website operators, helping us build a more intelligent and user-friendly content filtering function.

Frequently Asked Questions (FAQ)

  1. archiveFiltersWhere does the data source of the label come from? archiveFiltersThe label is mainly obtained from the custom parameters of the content model defined in the AnQiCMS backend (such as articles, products) as a filtering condition. When you add custom fields such as 'color', 'size', 'publish year' to the content model and set optional values for these fields, archiveFiltersIt can automatically render it as a frontend filter.

  2. If the user selects multiple filter conditions at the same time,IsCurrenthow will the property behave? IsCurrentThe property is for each independent filter condition item. Whether the user selects one condition or multiple conditions, as long as a specific filter option is selected, the correspondingval.IsCurrentproperty will be set totrueThis means you can easily add visual styles to all current active filters, allowing users to clearly see all the filters they have applied.

  3. IsCurrentDoes the attribute affect the filtering link (val.Link) generation? IsCurrentThe property is used only to mark and control the visual state of front-end elements, it is a boolean value indicating whether it is currently selected. The actual link of the filter condition (val.Link) is dynamically generated by AnQiCMS based on the current URL, the other selected filter conditions, and the configuration of the filter.IsCurrentIt does not directly participate in the link generation logic. It only determines its own state based on whether the generated link matches the current page URL.

Related articles

How to determine if a custom field exists or has a value in `archiveParams` before displaying it?

As an experienced website operation expert, I deeply know the powerful potential of AnQiCMS (AnQi CMS) in content management and website optimization.The flexible content model and customizable fields provide great convenience for us to build highly personalized websites.However, how to elegantly handle these dynamically generated custom fields in template design, ensuring that they are displayed only when they exist or have a value, is the key to improving template quality and user experience.

2025-11-06

How to render different input controls (such as text, radio, checkbox) in the `guestbook` form based on the `Type` attribute?

As an experienced website operations expert, I know that a flexible and versatile content management system is the foundation of website success.AnQiCMS (AnQiCMS) with its excellent flexibility and powerful customization capabilities has become an invaluable tool in our hands.Today, let's delve deeply into a very practical topic in actual operation: how to intelligently render different input controls, such as text boxes, radio buttons, or checkboxes, in the `guestbook` form of Anqi CMS according to the preset field types in the background.This is not just an implementation at the technical level

2025-11-06

How to dynamically add a required asterisk or hint based on the `Required` property of the `guestbook` form label?

As an experienced website operation expert, I know that every detail can affect user experience and operation efficiency.When building a website, forms are an important part of interacting with users, and clear, friendly form design is the key to improving conversion rates.AnQiCMS (AnQiCMS) with its flexible template engine and powerful backend management features, has provided us with great convenience, especially in handling scenarios such as message forms that require users to fill in information.Today, let's delve deeply into a seemingly simple but extremely practical skill: how to use the `Required` field of the back-end field

2025-11-06

How to determine if a comment in `commentList` has a parent comment (`Parent`) and display the reply structure?

As an experienced website operations expert, I fully understand how to effectively display user comments in content management, especially comments with reply structures, which are crucial for enhancing user interaction and website activity.AnQiCMS (AnQiCMS) relies on its powerful template engine and flexible data tags to make this requirement easily achievable.Today, let's delve into how to cleverly judge whether a comment has a parent comment in the AnQiCMS `commentList` tag and elegantly present a clear reply structure.

2025-11-06

How to elegantly handle empty list situations in AnQiCMS template using the `{% for ... empty ... %}` syntax?

In AnQiCMS template development, we often need to display a series of content lists, such as article lists, product lists, navigation menus, or friend links.However, these lists are not always filled with data. When the list is empty, how to elegantly inform the user that "there is no content here" instead of displaying a blank page or an error message has become a detail consideration in template design.AnQi CMS is well-versed in this, drawing on the excellent design of Django templates in its powerful template engine developed in Go language, providing us with `{% for ...

2025-11-06

How to use the `if` tag in combination with `forloop.Counter` to alternate the odd and even row styles of list items?

As an experienced website operation expert, I fully understand how to enhance user experience through detailed interface design in content presentation.AnQiCMS, with its high-performance architecture based on Go language and flexible template engine, provides us with great freedom to easily implement all kinds of creativity and features.

2025-11-06

How to use the `filter-contain` filter in AnQiCMS to check string or array containment in the `if` statement?

As an experienced website operations expert, I fully understand that in an increasingly complex network environment, efficient content management and flexible page display are crucial for improving user experience and SEO effectiveness.AnQiCMS (AnQiCMS) provides a series of practical tools with its high-performance architecture based on the Go language and the powerful features of the Django template engine.

2025-11-06

How to use the `filter-divisibleby` filter to determine the divisibility of a number in an `if` statement?

In AnQiCMS template development, achieving dynamic content display and fine-grained control is a daily challenge for website operation experts.AnQiCMS is highly praised for its concise and efficient template engine, which inherits the elegant style of Django templates, making content display and logical control intuitive.In website operation, we often need to present different content or styles based on the characteristics of numbers, such as displaying an advertisement every few products or setting different background colors for odd and even rows of the list.At this time, the `divisibleby` filter can be perfectly combined with the `if` statement

2025-11-06