As an experienced website operations expert, I often deal with content management systems in my daily work and know the importance of the flexible use of template tags for website performance and user experience.AnQiCMS (AnQiCMS) boasts its powerful functions and high performance brought by the Go language, making it the preferred choice for many enterprises and operational teams.WhenarchiveFiltersHow will it handle when a filter parameter dependent on the tag does not have a corresponding value?
archiveFiltersThe core function of the tag: data-driven filtering mechanism
In AnQi CMS,archiveFiltersTags are a very practical tool, designed to dynamically generate filtering conditions based on the various parameters of a document (archive).Imagine you are building a real estate website where users can filter property listings based on criteria such as 'property type' (such as residential, commercial) and 'property size' (such as single room, one bedroom living room) and other conditions.archiveFiltersTags are born for this kind of demand, they can intelligently extract all available filtering options from the existing content of your website and display them in a friendly manner to users.
The principle it works on is 'data-driven'.This means that it will not generate filter options out of thin air, but will 'scan' the custom fields defined in your current content model and check which values these fields contain in your actual documents.Only those values that actually appear in the content will be presented as filter options.
Two main cases of missing filter parameter values andarchiveFiltersprocessing
UnderstoodarchiveFiltersdata-driven characteristics, we can infer that when a filter parameter value is missing, its two main processing methods are:
Scenario one: The filter parameter (custom field) is not configured at all in the content model.If your content model (such as "property model") does not define the custom field "Has Elevator" at all, then
archiveFiltersThe label will naturally not include any filter conditions related to 'elevator' when generating the filter group.It will directly ignore this non-existent field.filtersvariable is, the "Has Elevator" ofitem(Filter group) will never appear infiltersthe array.Scenario two: The content model has defined parameters, but there are no corresponding values in the document or all values have been filtered.Assuming you have defined a custom field called "House Orientation" in your content model, but all your listing documents did not fill in the value of this field when published, or even if it was filled, the current list of documents viewed by the user after other filtering (such as area filtering) does not include the value of "House Orientation". In this case,
archiveFiltersThe display of the label may be slightly different:- The filter group (
item) may still be generated.Because this parameter is explicitly defined in the content model. - But the option list within the filter group (
item.ItemsIt will be empty.That is to say, although there will be a filter group with the title "House Orientation", there will be no specific options (such as "South-facing", "North-facing") for users to choose from below.
This handling method is reasonable because it still retains the presence of the filter parameter, but also realistically reflects that there are no available options to filter.
- The filter group (
The template elegantly handles missing values.
In actual template development, to provide a smooth user experience, we need to consider the above two cases and ensure that the template can elegantly handle empty lists that may occur, avoiding unnecessary empty filter groups or frontend errors.
The AnQi CMS template engine supports powerful loops and conditional judgment features similar to Django, which we can fully utilize. For example, when traversingarchiveFiltersGeneratedfiltersWhen a variable is declared, you can add a simple conditional statement:
{# 参数筛选代码 #}
<div>
<div>参数筛选:</div>
{% archiveFilters filters with moduleId="1" allText="默认" %}
{% for item in filters %}
{# 判断当前筛选组是否有可用的筛选选项 #}
{% if item.Items %}
<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>
{% else %}
{# 如果该筛选组没有选项,可以选择不显示,或者显示一个提示 #}
{# <div>{{item.Name}}: 暂无可用选项</div> #}
{% endif %}
{% endfor %}
{% endarchiveFilters %}
</div>
By{% if item.Items %}This judgment ensures that only when a filter group actually contains available filter options, it will be rendered, thus avoiding the appearance of an empty filter list on the page and enhancing the cleanliness of the user interface.
Content operation strategy suggestions
From the perspective of operation, this handling mechanism reminds us:
- Data filling integrity:Fill in all relevant custom fields as much as possible when publishing content, especially those fields defined as filter parameters in the content model.The integrity of the data directly affects the availability and richness of the filtering function.
- Rational planning of content models:When defining a content model and custom fields, it is important to fully consider the website's filtering needs. Fields that are not commonly used or have inconsistent data may not be suitable as front-end filtering parameters.
- User experience first:Even if some filtering parameters have no data, elegant degradation handling should be done in the template.You can hide the filter group or provide a friendly hint instead of displaying a blank area with no options.
In short, the Anqi CMS'sarchiveFiltersThe label demonstrated its intelligence and data-driven characteristics when handling missing filter parameter values.It will not forcibly generate options that do not exist, but will give feedback based on the actual content.As operation personnel, we should understand and utilize this mechanism, optimize content entry and template design, and provide users with an efficient, clear and satisfying filtering experience.
Frequently Asked Questions (FAQ)
Question: Why did I set up a custom field, but it didn't appear in the front-end filter list of the website?Answer: This is usually due to two situations: first, please check if the custom field is indeed defined in your content model and if it is set as a filterable parameter.Secondly, even if defined, it is necessary to ensure that at least one document has filled in the specific value for this custom field when published.
archiveFiltersTags are data-driven, and they are only displayed as filter options when actual values exist in the content.Ask: My filter condition title (such as "House Orientation") has appeared, but there are no options available below, is this normal??Yes, this is a normal situation.This indicates that the "house orientation
{% if item.Items %}), to control whether the filter condition title is displayed when the options are empty.Question:
archiveFiltersin the labelallText="全部"What is the specific function of the parameter? Where will it be displayed?Answer:allText="全部"The parameter is used to