How to get different thumbnail image addresses by using a filter in AnQiCMS template?

Calendar 👁️ 67

When using AnQiCMS for website content management, image management and optimization is a key factor in improving user experience, accelerating page loading speed, and enhancing SEO performance.Especially in the process of template development, we often encounter the need to obtain addresses of different size thumbnails.The AnQi CMS offers an intuitive way to deal with these issues with its concise and efficient design concept.

Today we will delve deeply into how to cleverly use built-in filters in the AnQiCMS template to obtain different thumbnail addresses for the images we upload.

The journey of the image in AnQiCMS: from upload to display

In AnQiCMS, whether through document management, category management, or uploading images to the image resource library, the system will process the images according to a set of predefined rules.When we upload an original image, AnQiCMS will intelligently generate one or more thumbnail versions to meet the various display needs of the website front-end.

Behind this 'intelligent generation' is离不开AnQiCMS back-endContent settings. You can access the back-end of后台设置-u003e内容设置.缩略图处理方式and缩略图尺寸Options. Here you can define the default width, height, and cropping mode of the system-generated thumbnails (for example, scaling proportionally by the longest side, cropping by the shortest side, etc.).These settings determinethumbThe specific size and appearance of the thumbnail returned when the filter is called.

For example, if your website needs to display a 50x50 pixel thumbnail in a small card and a 200x200 pixel image on the detail page, you need to understand that,thumbThe filter will return by defaulta set ofYou have configured the standard thumbnail size in the background "Content Settings". If it is indeed necessary to generate multiple fixed-size thumbnails on the server side (for example, 50x50 and 200x200 at the same time), AnQiCMS'sthumbThe filter does not support passing size parameters directly to dynamically generate.It will provide the standard thumbnail you have configured in the background.However, this does not mean that we cannot implement different sizes of display on the front end, more through flexible control of CSS.

RevelationthumbFilter: How to get thumbnail address

AnQiCMS's template engine supports syntax similar to Django, where filters are powerful tools for processing variable output. To get the thumbnail address of the uploaded image, we need to usethumbfilter.

Its basic usage is very concise: just use the image field as a variable and pass through the pipe|连接thumbthe filter.

{{ 图片地址 | thumb }}

Let's see its application in several common scenarios:

1. Get the cover thumbnail of a document, category, or single page

On the document detail page, category list, or single page content, we often call its cover image (usuallyLogoorThumbfield). These fields themselves may store the original image address, throughthumbfilter, we can easily obtain the thumbnail address after processing.

{# 获取当前文档的封面首图缩略图 #}
<img src="{{ archive.Logo | thumb }}" alt="{{ archive.Title }}" />

{# 获取当前分类的缩略图 #}
<img src="{{ category.Thumb | thumb }}" alt="{{ category.Title }}" />

{# 获取某个单页的封面缩略图 #}
{% pageDetail pageLogo with name="Logo" id="1" %}
<img src="{{ pageLogo | thumb }}" alt="单页标题" />

2. Process each image in a group image

Some content models support group images (for exampleImagesfield), it will return an array of image URLs. At this point, we need to combineforLoop to traverse each image and apply to each imagethumbfilter.

{# 假设 archive.Images 是一个图片地址数组 #}
<div class="gallery">
    {% for imgUrl in archive.Images %}
        <img src="{{ imgUrl | thumb }}" alt="图片描述" />
    {% endfor %}
</div>

3. Get the thumbnail of other modules (such as Banner)

Banner also usually has an image field (such asitem.Logo), you can also usethumbfilter.

{% bannerList banners %}
    {% for item in banners %}
        <a href="{{item.Link}}" target="_blank">
            <img src="{{ item.Logo | thumb }}" alt="{{item.Alt}}" />
        </a>
    {% endfor %}
{% endbannerList %}

Understand the practice of "different sizes"

As mentioned previously,thumbThe thumbnail address of the filter output, whose specific size is统一 configured in the background "Content Settings". If your requirement is to display the same image with different "visual sizes" at different positions on the front end, the most recommended and flexible way isCombine with CSS stylesto control.

For example, you can set images in CSS

Related articles

How to use the `yesno` filter of AnQiCMS to display 'yes', 'no', or 'unknown' status based on boolean values in the template?

In AnQi CMS template development, we often need to display different text in a user-friendly manner on the front page according to the boolean (true/false) status of background data, such as "yes" or "no."}Directly displaying `true` or `false` may seem too stiff, and writing complex `if-else` judgment statements can make template code look lengthy.Fortunately, AnQiCMS provides a simple and efficient solution - the `yesno` filter, which can help us easily convert boolean values to custom text states

2025-11-07

How does the AnQiCMS `wordwrap` filter implement intelligent automatic line breaks for long English paragraphs?

In daily content operations, we often encounter such a scenario: when long English paragraphs are published, they may exceed the container width on different devices or screen sizes, causing horizontal scroll bars to appear, which greatly affects the user's reading experience and the beauty of the page.AnQiCMS (AnQiCMS) fully understands this pain point and has provided a very practical template filter - `wordwrap`, which can cleverly solve the problem of automatic line breaking for long text.

2025-11-07

How to count word numbers with the `wordcount` filter of AnQiCMS when processing mixed Chinese-English text?

In Anqi CMS template design, the `wordcount` filter is a practical tool used to count the number of words in the text.For operation personnel and content creators, understanding the working principle, especially the statistical logic when dealing with mixed Chinese and English text, can help us accurately assess content length, optimize article structure, and better meet the needs of search engine optimization (SEO) and user reading experience.### `wordcount` filter basic usage The `wordcount` filter is very straightforward to use

2025-11-07

How to URL encode query parameters in AnQiCMS template to avoid conflicts with special characters?

When building dynamic links in the AnQiCMS template, we often need to pass variables as query parameters in the URL.For example, a search results page may need to pass the user's search term as a parameter;A category filter page may need to include the selected category ID or multiple filter conditions.However, these dynamic contents often contain special characters, such as spaces, `&`, and `?`Backticks, equals, slash, hash, etc., they have specific meanings in URLs.If these special characters are not processed, the browser or server may not be able to correctly parse the URL, resulting in a page error

2025-11-07

How to ensure that the AnQiCMS website content can adapt to display on different devices?

With the popularity of mobile internet, the types of devices used by users to access websites are increasingly diverse, ranging from desktop computers to tablet computers, and various sizes of smartphones. Whether the content of a website can be displayed smoothly and beautifully on different devices has become an important standard for evaluating the quality of a website.AnQiCMS (AnQiCMS) was designed with this need in mind, offering flexible and diverse solutions to ensure that website content can easily achieve adaptive display on multiple devices.

2025-11-07

What front-end display modes does AnQiCMS support to manage PC and mobile websites?

In the digital age, it is crucial to provide an excellent user experience whether visitors browse your website on a computer or mobile phone.A high-efficiency content management system should be able to flexibly meet this diverse display demand.AnQiCMS is designed for this, it provides various front-end display modes, allowing you to finely manage the display effects of PC and mobile websites according to your actual business needs.AnQiCMS provides three main display modes on the website frontend, each with unique advantages and applicable scenarios, helping you build a modern website adaptable to different devices

2025-11-07

How to customize the display layout and template file path for articles (or other content) in AnQiCMS?

In AnQiCMS, your website content display has high flexibility.Whether it is an article, product details, or an independent page, you can tailor the display layout and template file path according to the brand image, content characteristics, or specific operational needs.This design concept of AnQiCMS aims to help users break free from the constraints of traditional CMS and have more freedom to control the visual presentation and user experience of the website.

2025-11-07

How should the template files of AnQiCMS be organized and named to achieve flexible content display?

When using AnQiCMS to build a website, the organization and naming of template files are key to flexible content display, improving website maintenance efficiency and scalability.A well-structured and clearly named template system that not only allows you to easily manage various content types, but also lays a solid foundation for future functional expansion. ### Template File Storage and Basic Conventions AnQiCMS's template system uses a template engine syntax similar to Django, which makes it very亲切 for those familiar with front-end development.All template files should use the `.html` file extension uniformly

2025-11-07