If the category has not set Logo or Thumb, what path will `categoryList` return, and how to set the default image?

Calendar 👁️ 68

In the daily operation of AnQiCMS, the refined display of content is a key factor in improving user experience and the professionalism of the website.The importance of images as visual elements is self-evident.categoryListThis label may call category information and may encounter a situation where the category has not set the Logo or Thumb image, leading to blank or broken images being displayed on the front end.Today, let's delve into this issue and provide an elegant solution.

AnQiCMS incategoryListimage path behavior

In AnQiCMS,categoryListTags are used as a core tool for dynamically retrieving and displaying a website's category list. It allows us to easily traverse through various categories and obtain their related properties, including those we commonly use for visual display.LogoAnd usually refers to category large picture or Banner imageThumbField for category thumbnail.

So, when a category is in the background management interface, and the “thumbnail” or “Banner image” field has not uploaded any images,categoryListthe tag is called in the front-end templateitem.Logooritem.ThumbWhat will be returned? The answer is:An empty string path.

This means that if your template code directly uses{{ item.Logo }}or{{ item.Thumb }}as<img>label'ssrcProperty value, when the actual image path is empty, the browser will try to load an image with an empty path. This usually leads to the following kinds of adverse consequences:

  1. Browser displays a broken image icon:This is the most common phenomenon, seriously affecting the visual beauty and professionalism of the website.
  2. 404 error occurred:Browser is trying to load emptysrcWhen an image is requested, it may send a request to the server, causing the server to record a large number of 404 error logs, which may interfere with the troubleshooting of the website's real problems, and may also have a negative impact on search engine optimization (SEO).
  3. User experience is受损:Broken images are not only unattractive, but also make users feel that the website content is incomplete or improperly maintained.

To better understand, let's look at a simple template call example:

{% categoryList categories with moduleId="1" parentId="0" %}
    {% for item in categories %}
        <li>
            {# 如果item.Logo为空,这里会渲染成 <img src="" alt="分类名称 Logo"> #}
            <img src="{{ item.Logo }}" alt="{{ item.Title }} 分类Logo"> 
            {# 如果item.Thumb为空,这里会渲染成 <img src="" alt="分类名称 缩略图"> #}
            <img src="{{ item.Thumb }}" alt="{{ item.Title }} 分类缩略图">
            <h3>{{ item.Title }}</h3>
        </li>
    {% endfor %}
{% endcategoryList %}

Whenitem.Logooritem.ThumbWhen the field content is empty,srcThe attribute will eventually be empty, triggering the above problem.

An elegant solution: how to set the default image?

AnQiCMS provides two main default image settings that can work together, ensuring that the website maintains beauty and functionality in any situation.

Method one: Use the global content settings of AnQiCMS (recommended)

AnQiCMS has designed an intelligent default image processing mechanism, allowing you to set a global default thumbnail for website content.When the image of specific content is missing, the system will automatically use this global default image to fill in.

Set path:Log in to the AnQiCMS backend and navigate to"Backend settings" -> "Content settings".

Specific operations:In the "Content Settings" page, you will find an option named "Default thumbnail".Here, you can upload a placeholder image that you want to use as the default for the entire site.This image can be a company logo, a general category icon, or any image that can represent the content of your website.

Principle of effectiveness:Once you upload and save a default thumbnail here, AnQiCMS will intelligently use it as the default for all unsetLogoorThumbThe category (and documents, products, and other content) placeholder image. This means, regardless of which categoryitem.Logooritem.ThumbThe field is empty in the database, AnQiCMS will automatically convert it when rendering on the front endsrcThe attribute points to the path of this globally set default thumbnail, thereby effectively avoiding broken image phenomena and enhancing the consistency of the website.

The benefits of this method are:

  • Global coverage:One-time setting, effective throughout the site, greatly reduces maintenance costs.
  • System-level intelligent filling:No need to modify any template code, AnQiCMS will automatically handle it at the bottom level.
  • Consistency:Ensure that all missing image categories are displayed in a unified style.

Method two: make conditional judgments in the front-end template (flexible customization)

Although the global default thumbnail can solve most problems, in certain specific scenarios, you may want a category list to have its own unique default image, or use different placeholders for different list styles.At this time, we can use conditional judgment logic in the front-end template.

Setting method:Through Django template engine{% if ... %}and{% else %}tags, judgmentitem.Logooritem.ThumbIf it does not exist, specify a default image path manually.

Template code example:

{% categoryList categories with moduleId="1" parentId="0" %}
    {% for item in categories %}
        <li>
            {# 对Logo字段进行判断处理 #}
            {% if item.Logo %}
                <img src="{{ item.Logo }}" alt="{{ item.Title }} 分类Logo">
            {% else %}
                {# 自定义该列表的默认Logo图片,例如存放在 /public/static/images/ 目录下 #}
                <img src="/static/images/default_category_logo.jpg" alt="{{ item.Title }} 分类Logo (默认)"> 
            {% endif %}
            
            {# 或者对Thumb字段也进行类似处理 #}
            {% if item.Thumb %}
                <img src="{{ item.Thumb }}" alt="{{ item.Title }} 分类缩略图">
            {% else %}
                {# 自定义该列表的默认Thumb图片 #}
                <img src="/static/images/default_category_thumb.png" alt="{{ item.Title }} 分类缩略图 (默认)">
            {% endif %}
            <h3>{{ item.Title }}</h3>
        </li>
    {% endfor %}
{% endcategoryList %}

The advantage of this method lies in:

  • Highly customized:Different default images can be set according to different category lists or page requirements.
  • Flexibility:The default image can be an image resource within the site or an external link.

Please note:Specified in the template:/static/images/default_category_logo.jpgAt the following path, you need to manually upload the image file to AnQiCMS./public/static/images/Under the directory (or your custom static resource directory), make sure the path is correct.

**Practice and Suggestions

Combine these two methods to achieve the most flexible and lowest maintenance cost image management strategy:

  1. Set the global default thumbnail first:Make sure that even if you forget to make conditional judgments in the template, the website will not display broken images, which is the foundation of website stability.
  2. Use template conditional judgments for specific scenarios:When a category list needs a more personalized default image, use the template's`

Related articles

In multi-site management, how do you call the category data under other sites using `categoryList`?

As an experienced website operations expert, I am well aware that how to efficiently manage content and achieve data interconnectivity in a complex website ecosystem is the key to improving operational efficiency.AnQiCMS (AnQiCMS) with its powerful multi-site management capabilities, provides us with such possibilities.Today, let's delve into a very practical scenario in multi-site operations: how to elegantly call the classification data under other sites using the `categoryList` tag.### AnQi CMS Multi-Site Management: `categoryList`

2025-11-06

How to use the "offset,limit" mode in the `limit` parameter supported by `categoryList`, and what scenarios are applicable?

## Masterful Manipulation of Category List: Practical Use of AnQiCMS `categoryList`'s `offset,limit` Pattern As an experienced website operations expert, I am well aware of how important flexible data display capabilities are when building and optimizing website content.AnQiCMS with its concise and efficient features provides us with many powerful template tags, among which the `categoryList` tag is the core tool for managing website classification content. Today

2025-11-06

How to get the category details information of a specified ID through the `categoryList` tag instead of the current page?

As an experienced website operations expert, I know how important it is to flexibly obtain and display data when managing content.Especially when building the AnQiCMS website, we often encounter situations where we need to obtain specific category information rather than the context of the current page.Today, let's delve deeply into how to cleverly use AnQiCMS template tags to accurately obtain the category details you want.How to accurately locate: How to get the category details of a specified ID instead of the current page?In AnQiCMS template development, `categoryList` and

2025-11-06

How `categoryList` and `archiveList` work together to display the latest few documents under each category?

As an experienced website operations expert, I am well aware of the powerful aspects of a content management system (CMS), not only in terms of its backend functionality, but also in the flexibility of its frontend content display.AnQiCMS (AnQi CMS) is exactly such an outstanding tool, based on the high-performance architecture of the Go language,配合 its concise and efficient template tag system, it allows us to easily handle various complex content display needs. Today

2025-11-06

Does the `categoryList` tag support custom sorting rules to display the category list? (The document does not directly mention it, but it can be explored)

As an experienced website operations expert, I know that how to flexibly display and organize content in a content management system is the key to improving user experience and SEO effectiveness.AnQiCMS (AnQiCMS) provides a solid foundation for content operation with its efficient and customizable features.Today, let's delve deeply into a core issue about the `categoryList` tag: does it support custom sorting rules to display the category list?### Category List Label in AnQi CMS: `categoryList` Overview In AnQi CMS

2025-11-06

How to avoid `categoryList` automatically reading the current page category ID and force it to only display top-level categories?

In the flexible content management world of Anqi CMS, template tags are the bridge between us and data interaction.Among them, the `categoryList` tag is undoubtedly one of the core tools for building website navigation and content lists.However, senior operators often encounter a scene: when the website is on a specific category page, the `categoryList` tag will 'intelligently' read the current category ID and use it as the context for data display.This is extremely convenient in many cases, such as displaying the subcategories or peer categories of the current category.

2025-11-06

When will the `item.Content` field be used in the `categoryList` loop, can it display rich text content?

HelloAs an experienced website operations expert, I am willing to deeply analyze the application of the `item.Content` field in the `categoryList` loop of AnQiCMS (AnQiCMS), as well as how to elegantly display rich text content.

2025-11-06

`categoryList` can exclude certain specific category IDs from displaying in the list?

As an experienced website operations expert, I know how important it is to have fine control over the list content in content management.Especially in the context of increasingly complex website structures and increasingly rich content, how to flexibly display or hide specific content is directly related to user experience and operational efficiency.Today, let's delve into a common but cleverly handled requirement in AnQiCMS (`categoryList` tag) - whether it can exclude certain specific category IDs from displaying in the list.###

2025-11-06