As an experienced website operations expert, I know that how to flexibly use various tags to meet complex business needs is the key in such a powerful content management system as AnQiCMS. Today, let's delve into a topic aboutarchiveFiltersTag common questions:“archiveFiltersDoes the tag support setting the default value of the filter condition?


AnQiCMSarchiveFiltersTag: Can the default value of the filter condition be set? In-depth analysis and practical guide

In AnQiCMS,archiveFiltersTags are one of the core tools in template development for handling document filtering logic.It is mainly used to dynamically generate an interactive list of filter conditions for front-end users based on various parameters defined in the content model, such as filtering by 'apartment type', 'price range', and others on real estate websites, or by 'color', 'size' on e-commerce websites.This tag greatly simplifies the construction process of the dynamic filtering interface, making content display more flexible and personalized.

So, let's get back to today's topic,archiveFiltersDoes the tag support setting the default value for filter conditions? To put it directly,archiveFiltersThe tag itself does not provide a parameter to directly “set” a filter condition to be selected when the page is first loaded (i.e., the default value). Its main responsibility is to parse the URL parameters of the current page and then mark a certain option in the filter list as "selected" (IsCurrent)

To better understand this, let's delve into it a bit morearchiveFiltersThe working mechanism of the label and the parameters it provides.

archiveFiltersThe core function of the tag and parameter parsing

archiveFiltersThe label is usually used like this in the template:{% archiveFilters filters with moduleId=1 allText="全部" %}...{% endarchiveFilters %}.

It will be based on the content model you specify (viamoduleIdThe parameters) as well as the URL query parameters of the current page, output an array object containing multiple filtering dimensions (such as 'region', 'type')filtersEach filtering dimension includes a series of optional filtering values (such as "Beijing", "Shanghai"), which are presented in an array form.ItemsIt is presented in an array form.

One of the notable parameters isallTextIt allows you to customize the display text of the "All" option, such as setting it to "Unlimited", "All", etc. If you do not want to display the "All" option, you can also set it tofalse. From this perspective,allTextThis option indeed provides a 'default display text' for the special option 'All', but this is not what we usually understand as 'default selected' for a specific filter condition.

filtersEach object initemUnder theItemsEach in thevalAll contain three key attributes:

  • Label: The display name of the filter value, such as "Three bedrooms and one living room".
  • LinkClicking this filter value will redirect to the URL, which includes the corresponding query parameters, such as/fangchan?huxing=3shi.
  • IsCurrentA boolean value indicating whether the filter value is selected as the current URL parameter.This is automatically determined and marked by the AnQiCMS system based on the actual query parameters in the current page URL.

Just this one.IsCurrentProperty, revealsarchiveFiltersThe logic of handling the 'default value' label: it is aPassive reflectionThe label of the current URL state, not the label set by default actively.

How to implement the filtering effect of the 'default value'?

AlthougharchiveFiltersThe label does not set the default selected, but we can achieve the same purpose through other strategies, to achieve the effect of 'default selected' for a filter condition:

  1. Select by URL parameterThis is the most common and recommended way. When you want the user to see a selected filter condition by default when accessing a page, you can directly add the corresponding URL query parameters to the link.For example, if your property listing page is/fangchanIf you want to default display the housing information of 'Three bedrooms and one living room', then you can set the navigation link or advertising link to/fangchan?huxing=3shi. When the user accesses this URL,archiveFiltersthe tag will automatically detect,huxing=3shiand mark the filter option corresponding to "three bedrooms and one living room".IsCurrent: true.

  2. Front-end JavaScript Helper (for visual default in the absence of URL parameters)In some cases, you may want a specific filter option on the page to be visually highlighted by default when the user first accesses the page without any filtering parameters.This can be implemented using JavaScript. You can check if the current URL contains any filter parameters, and if not, manually add one to a certain filter option.activeClass name. This is just visually 'default', but it does not change the actual filtering logic. If the user does not interact with the filter, it will not automatically trigger data filtering.

  3. Backend route redirection or default queryFor more advanced requirements, the AnQiCMS backend (if you have permission for secondary development) can detect during request processing if the URL does not specify any filtering parameters, and then add a default filtering parameter internally, thenarchiveFiltersTags will still be correctly marked according to this backend processing parameterIsCurrent. But this goes beyondarchiveFiltersthe scope of the tag itself.

In summary, AnQiCMS'sarchiveFiltersTags are an efficient and flexible template tool, whichIsCurrentThe attribute perfectly responds to the filtering status in the URL parameters. Although it does not have a built-in 'default selected' setting, we can completely achieve the expected 'default filtering condition' effect by cleverly constructing the URL link, thereby providing a more intelligent and convenient content browsing experience.


Frequently Asked Questions (FAQ)

1. How can I make the user see the 'red' products by default when they visit the product list page?The most direct and effective method is to include the filter parameter "red" directly in the link to the product list page. For example, if your filter field iscolorThen you can set the link to/products?color=red.archiveFiltersThe tag will automatically parse this URL and mark the 'red' option as selected.

2.archiveFilterslabel'sallTextWhat is the difference between 'parameters' and 'set default value'? allTextThe parameter is used to set the display text of the 'All' option in the filter list, for example, displaying as 'No limit' or 'All.'It merely modifies the text label of the 'All' option. The 'Set Default Value' usually refers to the system automatically selecting a specific filter condition when there are no explicit filtering conditions, which is usually achieved through URL parameters or backend logic, rather than byallTextParameters controlled.

3. If the user has not specified any filtering conditions in the URL,archiveFilterswhat will the tag display?In this case,archiveFiltersThe label will generate all available filter options, but none of the specific filter values will be marked asIsCurrent(Currently selected). Usually, the 'All' or 'Unlimited' options are highlighted by default (if this logic is present in the template design), as they represent the state of no specific filters applied.