`categoryList`How to use the `empty` tag block when no categories are found, and how to customize prompt information?

Calendar 👁️ 67

As an experienced website operations expert, I know that every detail in the presentation of website content can affect the user experience and the professional image of the website.Especially in the scenario where data is "missing", how to avoid making the page look stiff, blank, and even confusing to users is a task that requires careful design.Today, let's delve into the Anqi CMScategoryListHow to use tags creatively when no category data is foundemptyTo customize friendly prompt information with tag blocks

categoryListThe challenge of the 'empty' tag usage

In AnQi CMS,categoryListTags are a powerful tool that allows us to dynamically retrieve and display website classification information (such as article categories, product categories, etc.) in templates. It enables us to base onmoduleId(Model ID),parentId(Parent category ID) and other parameters, flexibly filter and render the required category list.

Generally, we would useforto loop throughcategoryListThe category data obtained by the tag is displayed on the web page. However, under certain conditions,categoryListIf only simple labels are used when no matching category data is found,forThe loop, the area on the page will leave a blank space, which undoubtedly will bring a bad experience to the visitor, making them feel that the website content is incomplete, and even mistake it for a loading error.

AnQi CMS fully considers this scenario and provides us with an elegant solution, that isforin the loopemptytag blocks.

for empty endforOn stage: gracefully handle null data

The AnQi CMS template engine borrows the syntax style of Django, inforintroduced in the loopemptylabel block. The cleverness of this label block lies in the fact that it will only be displayed inforThe loop will only be executed when the data set to be traversed is empty (i.e., no iterable items are found). This means that whencategoryListNo category data can be found.emptyThe label block will appear, taking over the page display logic, allowing us to customize a prompt message instead of leaving a blank space.

Let's take a look at its basic structure:

{% categoryList categories with moduleId="1" parentId="0" %}
    {% for item in categories %}
        <!-- 这里是正常情况下,有分类数据时显示的内容 -->
        <li class="category-item">
            <a href="{{ item.Link }}">{{ item.Title }}</a>
            <p>{{ item.Description }}</p>
        </li>
    {% empty %}
        <!-- 当没有找到任何分类时,这里的内容会被渲染 -->
        <div class="no-category-tip">
            <p>抱歉,目前没有找到任何分类信息。</p>
        </div>
    {% endfor %}
{% endcategoryList %}

In this code block,{% for item in categories %}and{% endfor %}The content betweencategoriesis rendered when there is data in the list. While{% empty %}and{% endfor %}the content betweencategoriesThe list is rendered only when it is empty. In this way, we avoid the emptiness of the page and provide valuable feedback to the user.

Customize your prompt information: Make the empty page no longer 'empty'.

emptyThe strength of the tag block lies in its customizability. We can not only place simple text prompts, but also combine HTML structures, even use other built-in tags of AnQiCMS, to create richer and more guiding prompt information.

  1. Simple text prompt:The most direct way is to inform the user of the current status, with a friendly tone.

    {% empty %}
        <p>我们正在努力更新中,暂无相关分类,请稍后再来。</p>
    {% endfor %}
    
  2. Add HTML structure to enhance readability:Usediv/p/h3Tags can make prompt information more hierarchical and attract users' attention.

    {% empty %}
        <div class="no-category-found-box">
            <h3>哎呀,这里空空如也……</h3>
            <p>我们正在积极整理内容,很快就会有新的分类上线!</p>
            <p>您可以探索网站其他区域,或许会有您感兴趣的内容。</p>
        </div>
    {% endfor %}
    
  3. Combine other tags to provide dynamic information:This is a skill commonly used by operation experts, taking advantage of the flexibility of CMS to make prompts more intelligent. For example, we can usesystemtags to get the website name, orcontactLabel to obtain contact information, guide the user to the next step.

    {% categoryList categories with moduleId="1" parentId="0" %}
        {% for item in categories %}
            <!-- ... 分类列表内容 ... -->
        {% empty %}
            <div class="empty-state-message">
                <p>当前区域暂无分类信息。</p>
                <p>建议您访问 <a href="/">{{ system with name="SiteName" }}</a> 首页,或通过站内搜索功能查找您感兴趣的内容。</p>
                <p>如有疑问,欢迎联系我们:<a href="tel:{{ contact with name="Cellphone" }}">{{ contact with name="Cellphone" }}</a></p>
            </div>
        {% endfor %}
    {% endcategoryList %}
    

    In this example, when there is no category, the user will see a prompt containing the website name and contact phone number, which is both professional and practical.

  4. Guide admin operations (if applicable for backend templates):In some backend management interfaces or developer views,emptyBlocks can also be used to prompt administrators to create content.

    {% empty %}
        <div class="admin-tip">
            <p>当前模型下没有创建任何分类。赶紧去 <a href="/system/category/create">创建您的第一个分类</a> 吧!</p>
        </div>
    {% endfor %}
    

    Of course, the aforementioned/system/category/createThe path is an example, the actual path should be determined according to your AnQiCMS backend routing.

Enhancing user experience: Details determine success or failure

Handle properlycategoryListThe empty data state is not just about avoiding blank pages on the page, it is also a key factor in improving user experience and maintaining the professional image of the website. A carefully designed 'empty' state prompt can:

  • Reduce user confusion:Clearly inform the user that there is no content at the moment, rather than letting them guess whether the page has failed to load.
  • Guide user behavior:Encourage users to continue exploring the website by providing navigation links, a search box, or contact information, rather than leaving directly.
  • Maintain the brand tone:Even an 'empty' page can convey the professionalism and warmth of the brand through friendly copy and design.

In short, the Anqi CMS'semptyThe tag block provides a very flexible and powerful mechanism to deal with.categoryListA state of no data may occur. As a website operator, we should make full use of this feature to transform potential 'blanks' into opportunities to enhance user experience and website value.

Frequently Asked Questions (FAQ)

  1. Q:emptyLabel block andif categoriesWhat is the difference?A:{% for ... %}{% empty %}{% endfor %}The structure isforThe loop is unique, it executes when the loop data is emptyemptyblock. And{% if categories %}Need to be written extraforloop and{% else %}Block to handle empty cases.emptyLabel block makes the code structure more concise, the intention clearer, and is a practice when dealing with loop empty data.

  2. Q: Can IemptyDo you use other AnQiCMS template tags in the tag block?A: Of course you can.emptyThe tag block can contain any valid HTML structure, CSS styles, and other template tags provided by AnQiCMS (such assystem/contactwait,so that you can create richer and dynamic prompt information.

  3. Q: IfcategoryListThe parameter of the tag itself is incorrect,emptyWill the block still be executed?A: IfcategoryListThe parameters of the tag cause the query to fail (for examplemoduleIdDoes not exist, this usually leads to template rendering errors rather than returning an empty list.emptyA block only whencategoryList Executed successfully but the result set is empty.It will trigger in such a case. For system-level issues caused by parameter errors, you need to check the logs or AnQiCMS backend error information.

Related articles

How to quickly view all available fields and values of the `categoryList` returned item object during template debugging?

During the development and debugging of Anqi CMS templates, we often need to gain a deep understanding of the data structure returned by template tags in order to control the display of page content more accurately.Especially like the `categoryList` such list tags, it will loop to output multiple `item` objects, each carrying rich data.How can we quickly and comprehensively view the available fields and their corresponding values in the `item` object returned by `categoryList` when debugging?

2025-11-06

Can the `moduleId` parameter of the `categoryList` tag specify multiple model IDs for a union query?

As an experienced website operations expert, I have a deep understanding of the powerful functions and flexible template system of AnQiCMS (AnQiCMS).In daily content operations, we often encounter the need to aggregate and display different types of content.Today, let's delve into the usage of the `categoryList` tag's `moduleId` parameter, especially the issue of whether it can specify multiple model IDs for a joint query.

2025-11-06

How to implement the display of the 'sibling categories' of the current category in `categoryList`, instead of the subcategories?

AnQi CMS is an efficient and customizable content management system, playing an important role in website operations.Its template system is powerful and flexible, allowing operators to finely control the display of content according to actual needs.Today, let's delve into a common issue in actual operation that beginners may find confusing: how to cleverly display 'sibling categories of the current category' in the `categoryList` tag, rather than its subcategories.It is of great significance to display the brother category list in terms of content organization and user experience.

2025-11-06

`categoryList`Does it support filtering or displaying based on custom fields by category?

HelloAs an experienced website operations expert, I know the importance of a flexible content management system for efficient operations.AnQiCMS stands out among many CMS systems with its excellent customizability, especially in content modeling and category management, providing great convenience.However, many operators may wonder a question when using the `categoryList` tag: does it support filtering or displaying based on custom fields of categories?

2025-11-06

Is the `categoryList` tag returning categorized data real-time from the database or does it have an in-built caching mechanism?

In the daily operation of website management, the speed and efficiency of data access are core elements of user experience and search engine optimization.For systems like AnQiCMS (AnQiCMS) that are dedicated to providing efficient and customizable content management solutions, whether the internal data processing mechanism, especially tags like `categoryList` that are frequently called, always directly query the database or have an intelligent caching mechanism, is a focus of many operators.

2025-11-06

How to limit the display quantity of each subcategory level when nesting multi-level categories?

AnQiCMS is an efficient and flexible content management system that excels in building structured content, especially its multi-level classification feature, which helps us clearly organize website content.However, when displaying multi-level category nesting, we often encounter a challenge: how to elegantly control the display quantity of each sub-category level to avoid the page being too long or the load being too heavy?As an experienced website operation expert, I am well aware of the importance of this requirement. Today, I will delve into the exquisite way to achieve this goal in AnQiCMS with everyone.

2025-11-06

What is the corresponding relationship between the `categoryList` tag and the classification related fields in the background `content model` settings?

As an experienced website operations expert, in my practice with AnQiCMS, I deeply understand that its flexible and powerful content management capabilities are the cornerstone of website success.Today, let's delve into a seemingly simple but highly flexible core mechanism: the `categoryList` tag and the correspondence relationship of classification-related fields in the background `content model` settings.Understanding this can help you control the presentation of website content more finely, realizing truly customized operation strategies.

2025-11-06

Can it be implemented to create a category list based on alphabetical index through `categoryList`?

As an expert who deeply understands website operation and is well-versed in all the functions of AnQiCMS, I often encounter various inquiries about the form of content presentation.TodayOn many content-rich websites, especially those that contain a large number of product categories, person entries, or professional terminology, there is a classified index list arranged in alphabetical order

2025-11-06