How to display the introduction and Banner image of the current category in the AnQiCMS template?

Calendar 👁️ 75

In website operation, how to make your category page more attractive while clearly conveying information is the key to improving user experience and SEO effectiveness.AnQiCMS (AnQiCMS) relies on its flexible template system, allowing you to easily display the introduction of the current category and personalized Banner images on the category page.

Next, we will explore how to implement this feature in the AnQiCMS template, making your website category page more vivid and professional.

1. Deeply understand the AnQiCMS template system

The template creation of AnQiCMS adopts a syntax similar to the Django template engine, which means you will mainly use two types of tags:

  • double curly braces{{ 变量 }}: is used to output the value of a variable.
  • single curly braces and percent signs{% 标签 %}: Used for controlling logic, such as conditional judgments (if), loop (for) and calling built-in function tags.

All template files are stored in/templatethe directory, and.htmlas a file extension. The templates for category pages are usually named{模型table}/list.htmlor customizedlist-{分类ID}.htmlIn these templates, AnQiCMS will automatically provide the context data of the current category, making it convenient for you to directly call it.

2. Get and display the introduction of the current category.

The category introduction is an important window for quickly introducing the content of this category to visitors. In AnQiCMS, you can easily obtain this information throughcategoryDetailtags.

In the background, on the "Content Management" -> "Document Category" page, when editing the category description you need to set, there will be a "Category Description" field.Here you can fill in the text content, which can be called in the front-end template.

To display the introduction of the current category, you can write the code in the template like this:

<div class="category-description">
    {# 使用 categoryDetail 标签获取当前分类的描述信息,并使用 |safe 过滤器防止HTML转义 #}
    {% categoryDetail currentCategoryDescription with name="Description" %}
    {{ currentCategoryDescription|safe }}
</div>

Code analysis:

  • {% categoryDetail currentCategoryDescription with name="Description" %}: This is a powerful tag that retrieves the details of the current category.name="Description"The parameter specifies that we need to retrieve the introduction content of the category.currentCategoryDescriptionIt is a custom variable name used to store the retrieved introduction text.
  • {{ currentCategoryDescription|safe }}The obtained summary text will be output to the page.|safeThe filter is very important here because the category summary content may contain HTML tags (such as bold, links, etc.), using|safeEnsure that these HTML contents are correctly parsed and displayed by the browser, rather than being output as plain text.

3. Display the Banner image of the current category.

A beautifully designed Banner image can instantly catch the visitor's attention and enhance the visual appeal and professionalism of the page.The AnqiCMS allows you to set multiple Banner images for each category.

In the background "Content Management" -> "Document Category" page, when editing categories, there will be a "Banner Image" option.You can upload one or more images here.

Due to the support of multiple image uploads for the Banner image, when it is called in the template, it is returned as an array of image URLs. You need to use a loop to iterate over and display them.

3.1 Display all Banner images

If you want to display all uploaded Banner images in a carousel, you can do this:

<div class="category-banner-slider">
    {# 获取当前分类的所有 Banner 图片 #}
    {% categoryDetail categoryBanners with name="Images" %}
    {% if categoryBanners %}
        {% for imageUrl in categoryBanners %}
        <img src="{{ imageUrl }}" alt="{% categoryDetail with name='Title' %} Banner" class="category-banner-image">
        {% endfor %}
    {% else %}
        {# 如果没有设置 Banner 图,可以显示一个默认占位图或不显示 #}
        <img src="/public/static/images/default-banner.webp" alt="默认Banner" class="category-banner-image">
    {% endif %}
</div>

Code analysis:

  • {% categoryDetail categoryBanners with name="Images" %}Get the URL array of all Banner images associated with the current category and store it incategoryBannersthe variable.
  • {% if categoryBanners %}: CheckcategoryBannersCheck if the array is not empty to ensure that only images uploaded are displayed.
  • {% for imageUrl in categoryBanners %}:TraversecategoryBannersarray,imageUrlThe variable will get the URL of an image in each loop.
  • <img src="{{ imageUrl }}" alt="{% categoryDetail with name='Title' %} Banner" ...>: Use.<img>The label displays the image.altAttributes are very important for SEO and accessibility, here we called the title of the current category asalttext, making it more semantically meaningful.

3.2 Display the first Banner image only

In many cases, you may only need to display the first image in the category Banner, such as the header large picture of the page.

<div class="category-banner-header"
     {% categoryDetail categoryBanners with name="Images" %}
     {% if categoryBanners %}
        {# 获取数组中的第一张图片URL #}
        {% set firstBannerUrl = categoryBanners[0] %}
        style="background-image: url('{{ firstBannerUrl }}');"
     {% else %}
        {# 如果没有设置 Banner 图,可以设置一个默认背景 #}
        style="background-image: url('/public/static/images/default-header.webp');"
     {% endif %}
     >
    {# Banner 区域内的其他内容,比如分类标题等 #}
    <h1>{% categoryDetail with name="Title" %}</h1>
</div>

Code analysis:

  • {% set firstBannerUrl = categoryBanners[0] %}: By index[0]Directly obtaincategoryBannersThe first element in the array, which is the URL of the first Banner image.
  • style="background-image: url('{{ firstBannerUrl }}');": Set the obtained image URL todivThe background image of the element. This method is often used for responsive large images or banners that need to cover content.
  • {% categoryDetail with name="Title" %}: Call the category title again, which can be used for text information on the Banner.

4. Integrate into your category template.

Integrate the above code snippet into your category list page template (for examplearticle/list.htmlorproduct/list.html), which is usually placed at the top or main area of the page content.

”`twig {% extends ‘base.html’ %} {# Inherit your base template #}

{% block content %}

<div class="category-header">
    {# 获取当前分类的标题,作为页面主要标题 #}
    <h1>{% categoryDetail with name="Title" %}</h1>

    {# 显示分类简介 #}
    <div class="category-intro">
        {% categoryDetail categoryDesc with name="Description" %}
        {{ categoryDesc|safe }}
    </div>

    {# 显示分类 Banner,这里选择只显示第一张作为头部背景 #}
    <div class="category-main-banner"
         {% categoryDetail categoryBanners with name="Images" %}
         {% if categoryBanners %}
            {% set firstBannerUrl = categoryBanners[0] %}
            style="background-image: url('{{ firstBannerUrl }}');"
         {% else %}
            style="background-image: url('/public/static/images/default-category-banner.webp');"
         {% endif %}
         >
        {# 您可以在 Banner 上叠加其他元素,例如分类名称或标语 #}
    </div>
</div>

<div class="category-content">
    {# 这里放置您的文档列表标签,例如 archiveList,用于显示分类下的文章或产品 #}
    {% archiveList archives with type

Related articles

How to display hreflang tags for users of different languages on the AnQiCMS website?

In the operation of multilingual websites, it is crucial to ensure that search engines can accurately understand the language and region targeted by your content, which is essential for improving user experience and search engine optimization (SEO).The `hreflang` tag is the key tool to solve this problem.It tells search engines that your site has content variants for different languages or regions, thus avoiding duplicate content issues and helping search engines to display the most relevant pages to users of different languages.

2025-11-09

How to format the timestamp into the display format of 'Year-Month-Day Hour:Minute' in AnQiCMS template?

In website content management, the clear display of time information is crucial for user experience.Whether it is the release date of an article or the submission time of comments, a format that conforms to reading habits can make information communication more effective.AnQiCMS provides flexible template functionality, allowing us to easily format timestamps.

2025-11-09

How to display the user nickname, comment content, and posting time in the AnQiCMS comment list?

In AnQiCMS, the comment feature is an important part to enhance the interaction of the website.How to clearly and beautifully display the valuable comments left by users on the website, which is a focus for website operators.AnQiCMS provides flexible template tags, allowing us to easily customize the display of the comment list, including user nicknames, comment content, and publishing time, etc.To implement the display of comment lists, we mainly use the AnQiCMS template tag system.This usually involves editing the specific parts of the website template file. ### 1.

2025-11-09

How does the AnQiCMS template display or hide specific content based on user group permissions?

In website operation, displaying or hiding specific content based on user identity is a common strategy, which can help us meet various business needs such as member exclusive, paid content, and internal information distribution.AnQiCMS provides flexible user group management features, combined with its powerful template engine, it can easily implement content control based on user group permissions. ### Learn about AnQiCMS user group mechanism AnQiCMS is built with a complete user group management and VIP system.In the background, we can create different user groups

2025-11-09

How to dynamically generate page Title, Keywords and Description using `tdk` tag in AnQiCMS template?

In today's internet environment where content is exploding, Search Engine Optimization (SEO) is crucial for a website's visibility.And the Title (title), Keywords (keywords), and Description (description) on the website page, which we commonly call TDK, are key factors for search engines to understand page content, decide whether to display it to users, and whether users will click.In AnQiCMS, a content management system designed specifically for small and medium-sized enterprises and content operation teams, dynamically generating these TDK information is to enhance the website

2025-11-09

How to implement multi-condition filtering display on the article list page with the `archiveFilters` tag of AnQiCMS?

It is crucial to provide users with a convenient and accurate content search experience in website operation.As the content of the website becomes richer, simple classification or keyword search is often not enough to meet the personalized needs of users.At this time, the multi-condition filtering function on the article list page is particularly important.For AnQiCMS users,巧妙利用 `archiveFilters` tag can easily achieve this goal, making your article list page instantly possess powerful filtering capabilities.

2025-11-09

How to automatically convert plain text URLs of articles in the AnQiCMS template to clickable hyperlinks?

In daily website content operations, we often need to mention some external links or URLs in articles, product descriptions, or single-page content.If these URLs appear only in plain text, visitors will not be able to click and jump directly, which will undoubtedly affect the user experience, and may even cause some important information to be ignored.AnQiCMS as a powerful content management system, provides a simple and efficient way to solve this problem, making your content more vivid and interactive.AnQiCMS uses a template engine syntax similar to Django

2025-11-09

How to prevent content scraping on the front end in AnQiCMS, such as displaying watermarks or interference codes?

Protect Originality: AnQiCMS intelligent strategy for front-end content collection prevention In the era of explosive Internet content, the value of original content is becoming more and more prominent, but it also faces the risk of malicious collection.The hard work we put into writing and carefully designed images can be stolen in an instant by others, not only infringing on the creators' labor成果, but also potentially affecting the website's SEO performance and brand image.How can we effectively protect our digital assets?AnQiCMS (AnQiCMS) provides a very practical built-in solution to this issue

2025-11-09