In AnQi CMS template, how to automatically get the thumbnail version of a dynamically generated image URL (such as `{{item.Logo}}`) through the `thumb` filter?

Calendar 👁️ 83

In website content operation, images are an indispensable element for improving user experience and conveying information.However, how to ensure image quality while considering the loading speed and layout beauty of the website, especially when there are a large number of images and dynamic generation of sources, has become a challenge faced by many operators.AnQiCMS as an efficient and flexible content management system provides us with an elegant solution, including the handling of dynamic image URLs and automatically obtaining thumbnailsthumbfilter.

Why do we need thumbnails?

We all know that large image files can significantly increase the loading time of web pages, which not only affects user experience but also is不利 for search engine optimization (SEO).A website that can respond quickly often retains more visitors.The introduction of the thumbnail is to solve this problem.It allows us to use smaller, faster-loading image versions in places that need to display multiple images on list pages, sidebars, etc., and only load the original large image when the user clicks to view details.In addition, uniform thumbnail specifications can also make the page layout more tidy and professional.

How does AnQiCMS intelligently handle image resources?

AnQiCMS considers image processing very carefully.In the "Content Settings" in the background, we can find detailed configuration items about the "thumbnail processing method" and "thumbnail size".The system supports various scaling methods, such as uniform scaling by the longest side, padding by the longest side, or trimming by the shortest side, and can also customize the uniform size of thumbnails.This means that no matter the size of the original image we upload, AnQiCMS can automatically generate thumbnail versions that match the website's style.

In the template, AnQiCMS usually provides us withitem.Logo(Original image URL) anditem.Thumb(System-generated thumbnail URL) such field. But sometimes, we may only obtain the original image URL, or we want to process a thumbnail for any image URL, at this timethumbThe filter comes into play.

thumbThe magic of the filter

In the AnQiCMS template system, we usually use syntax similar to the Django template engine. It comes with many practical filters (filters),thumbOne of them.thumbThe main function of the filter is to receive a complete image URL as input, then automatically return the thumbnail version URL of the corresponding image based on the thumbnail rules configured in the background "Content Settings".This greatly simplifies the template code, avoiding the cumbersome operation of manually concatenating thumbnail path.

Its core advantage lies in:

  • Dynamic adaptability:No matter whether the image URL comes from an article, product, page or any other dynamic content, as long as it is a valid image address,thumbThe filter can handle it.
  • Centralized management:The thumbnail generation rules, size, etc. can be uniformly configured in the AnQiCMS backend. The template code only needs to pay attention to the call of the picture and does not need to be modified to adapt to the changes of the backend rules.
  • Performance optimization:Make sure the front-end page always loads images of the appropriate size to enhance website performance.

How to use in the templatethumbFilter?

UsethumbThe filter is very simple and intuitive, just apply it after the variable containing the image URL and use|separated by symbols.

Assuming we are iterating over a list of articles,item.Logofield contains the original URL of the cover image of the article. We want to display thumbnails of these images on the list page:

{% archiveList archives with type="list" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            {# 使用thumb过滤器获取缩略图 #}
            <img src="{{ item.Logo|thumb }}" alt="{{item.Title}}">
            <h5>{{item.Title}}</h5>
        </a>
    </li>
    {% empty %}
    <li>
        该列表没有任何内容
    </li>
    {% endfor %}
{% endarchiveList %}

In the code above,{{ item.Logo|thumb }}The conversion from the original image URL to the thumbnail URL is complete.

Similarly, if we upload a Banner image in the page configuration when displaying a single page detail, and its URL is stored in a variable (for examplepageBannerIn this way, we can also handle it:

{% pageDetail pageImages with name="Images" %}
{% if pageImages %}
    {# 假设我们只想展示第一张Banner图的缩略图 #}
    {% set pageBanner = pageImages[0] %}
    <div class="page-banner" style="background-image: url('{{ pageBanner|thumb }}');">
        <!-- 其他内容 -->
    </div>
{% endif %}
{% endpageDetail %}

You can see, regardless of the source of the image is:item.LogoWhether it is an element in the array, or other dynamic variables, as long as their value is a picture URL string,thumbThe filter can convert it into the thumbnail link we expect.

Configuration behind the scenes: Thumbnail management center

thumbThe filter works normally due to the powerful image management function of AnQiCMS backend. You can find the thumbnail configuration options in "Backend Settings" -> "Content Settings":

  • Thumbnail processing method:Choose whether to scale proportionally, pad, or crop. This determines the thumbnail generation strategy.
  • Thumbnail size:Set uniform width and height. For example, set to 200x150 pixels, all throughthumbImages processed by the filter will attempt to generate this size thumbnail.
  • Default thumbnail: When certain content does not have an uploaded image, you can specify a default image as a placeholder.
  • Batch regenerate thumbnails:If you change the thumbnail size or processing method, you can use this feature to one-click update the thumbnail version of all uploaded images to ensure the site's style is unified.

These are the settings.thumbThe foundation of filter behavior, reasonably setting them will help you better optimize website images and improve overall operational efficiency.

In summary, AnQiCMS'sthumbThe filter is a very practical tool, it extracts the generation and management of image thumbnails from the template code, allowing template developers to focus on content display, while website administrators can flexibly adjust the image strategy through the backend.Make good use of this feature, and your website will achieve significant improvements in visual effects and loading performance.


Frequently Asked Questions (FAQ)

1. Why did I usethumbFilter, but the size of the displayed image on the front end has not changed?

This usually has several reasons. First, please check if the thumbnail size is configured in the AnQiCMS backend "Content Settings", if not set, the system may not generate thumbnails of a specific size.Secondly, browser caching may cause image updates to be不及时, try clearing the browser cache or accessing in incognito mode.Finally, if the original image is already very small, smaller than the thumbnail size you set, then even after passing through the filter, the image size will not increase.

2.thumbDoes the filter create thumbnail versions for all images? Even if these images are not uploaded through the AnQiCMS backend?

thumbThe filter mainly processes images uploaded through the AnQiCMS backend, as the system will record and manage these images. When you willthumbWhen the filter is applied to an original image URL, AnQiCMS will attempt to locate or generate the corresponding thumbnail according to its backend configuration. If the image URL points to an external website or a local image not managed by AnQiCMS,thumbThe filter may not work or may only return the original URL. By default, AnQiCMS will intelligently download remote images in the article content to the local and manage them (if the background option 'Download remote images' is enabled), so thatthumbThe filter can process it.

Can I use different thumbnail sizes for different images? For example, article lists and article detail pages need different sizes of thumbnails.

thumbThe filter itself does not accept size parameters, it will uniformly apply the global thumbnail processing method and size defined in the background 'Content Settings'. If you need to display thumbnails of different sizes at different locations, consider the following methods:

  • Backend multi-field support:If your content model supports multiple image fields (such asitem.LogoSmallanditem.LogoLarge), you can differentiate them during upload and in the template

Related articles

How to use the `stringformat` filter to generate a numeric string with leading zeros or a specific width in AnQi CMS (such as order numbers)?

In website operation, we often need to handle various number strings with specific formats, such as order numbers, product codes, or member IDs.These numbers usually need to maintain a certain length, and leading zeros are used to fill in when the numbers are insufficient to ensure uniformity and aesthetics.AnQiCMS (AnQiCMS) provides a very practical template filter——`stringformat`, which can help us easily meet these needs.

2025-11-08

Does the `stringformat` filter support custom internationalization format output for datetime objects?

In the daily operation of the website, we often need to display date and time information in a user-friendly manner.Especially when facing users from different regions, it is particularly important to be able to output date and time formats that conform to local customs, which is what we commonly refer to as 'internationalized format output'.Today, let's talk about a commonly used filter `stringformat` in AnQiCMS, and see if it supports this customized internationalized format output for date and time objects.

2025-11-08

In the Anqi CMS backend custom field, if a field stores a URL, how can you use the `stringformat` filter to validate its format in the template?

Storing URLs in the AnQiCMS backend custom fields is a very practical feature, allowing us to add various personalized information to content models based on business needs.However, when these URLs need to be displayed in front-end templates, we not only need to ensure that they can be output correctly, but sometimes we also hope to perform some basic format checks to enhance the robustness and user experience of the page.

2025-11-08

Can the `stringformat` filter convert a Go language slice or Map into a readable JSON string output?

When developing templates for AnQiCMS, we often encounter such questions: The background data is a slice (Slice) or map (Map) structure in Go language, and if we want to output these data in a readable JSON string format in the front-end template, can the `stringformat` filter built into AnQiCMS handle it?This is indeed a very practical requirement, after all, JSON format is ubiquitous in modern web development.

2025-11-08

Does the `thumb` filter in AnQi CMS support specifying the width and height of the thumbnail, or only fetching the cropped URL?

When using Anqi CMS for website content management, we often need to handle images, especially thumbnails for articles or products.This is when the `thumb` filter comes into play.It can help us easily generate and obtain the thumbnail address from a complete image address.However, many friends may be curious, does this `thumb` filter support specifying the width and height of thumbnails directly when used?Or is it just returning a cropped image URL?

2025-11-08

How to use the `stringformat` filter in Anqi CMS templates combined with `if` tags to output different string descriptions based on the value size?

In website operation, we often encounter the need to dynamically adjust the display content of the page based on data.For example, a product page may display "Sufficient stock", "Tight stock" or "Temporarily out of stock" based on the inventory quantity; a user points page may display "Regular member", "Senior member" or "VIP member" based on the points level.

2025-11-08

How to use the `repeat` filter in Anqi CMS template to quickly generate repeated placeholders or decorative strings?

In AnQi CMS template design, flexibly using various filters (Filter) is the key to improving template performance and development efficiency.Among them, the `repeat` filter provides a very convenient solution for quickly generating repetitive placeholders or decorative strings with its concise characteristics.`repeat` filter, as the name implies, is mainly used to repeat a specified string or variable content according to the number of times set.

2025-11-08

How to implement batch string replacement with the `replace` filter in AnQi CMS, especially when performing SEO keyword optimization?

AnQiCMS, with its flexible and efficient features, has become a powerful assistant for many content operators to improve their website performance.In website operation, especially when performing SEO keyword optimization, the accuracy and timeliness of content are crucial.Today, let's delve deeply into a seemingly simple yet powerful tool in Anqi CMS—the `replace` filter, and how to巧妙运用it巧妙运用it effectively to achieve batch replacement of strings, thereby making your SEO keyword optimization work twice as effective.### One

2025-11-08