What is the default character used for filling by the `center`, `ljust`, and `rjust` filters in the AnQiCMS template?

Calendar 👁️ 66

The AnQiCMS template system provides a rich set of filters (filters) to help us format and process content. When performing text alignment operations,center/ljustandrjustThese filters are commonly used tools. They can center, left-align, or right-align our text content within a fixed width.When first encountering these filters, many users may be curious, what characters will the system use to fill the blank areas when the text length is shorter than the specified width?

Below, we will discuss the functions of these three filters and their default padding characters one by one.

centerFilter: Align text to center

centerThe filter's role is to center a string within a specified total length.If the length of the original string is less than the total length we set, it will automatically fill characters on both sides of the string to achieve centering.

Default padding character: ForcenterFor a filter, when the string length is insufficient, it will use by defaulthalf-width spaceFill in the blanks on both sides. If the total number of spaces to be filled is odd, the right side is usually one less than the left to maintain visual centering balance.

Usage example:

Suppose we want to center the string"test"within a 20-character wide area:

'{{ "test"|center:20 }}'

Output Result:

'        test        '

It is clearly visible from the results that the string"test"It is placed in the middle, with half-width spaces on both sides, making the total length reach 20 characters.

ljustFilter: Implement text left alignment

ljustThe filter is used to left-align a string within a specified total length.This means that if the length of the original string is less than the set total length, it will automatically fill the characters on the right side of the string.

Default padding character: andcenterFilter is the same,ljustThe filter will also be used by default when it needs to be filledhalf-width spaceto fill the right side of the string.

Usage example:

To string"test"Left-aligned within a width of 20 characters:

'{{ "test"|ljust:"20" }}'

Output Result:

'test                '

As you can see,"test"The string is close to the left, and enough half-width spaces are filled on the right to reach a total length of 20.

rjustFilter: Implement text right alignment

rjustThe filter is used to right-align a string within a specified total length. If the length of the original string is less than the set total length, it will automatically fill characters on the left side.

Default padding character: Similarly,rjustThe filter also uses the default fillinghalf-width spaceto fill the spaces on the left side of the string.

Usage example:

To string"test"Right-aligned within a width of 20 characters:

'{{ "test"|rjust:"20" }}'

Output Result:

'                test'

This time,"test"The string is right-aligned, the left side is filled with half-width spaces, ensuring the entire output length is 20.

Summary

Through the above introduction, we can clearly understand that the AnQiCMS template includescenter/ljustandrjustThese text alignment filters, when performing character padding, use the default and unified padding characters arehalf-width spaceThis makes text alignment in templates simple and intuitive, achieving neat formatting without additional configuration.


Frequently Asked Questions (FAQ)

Q1:center/ljust/rjustDoes the filter support custom padding characters?

A1:According to the design of the AnQiCMS template filter,center/ljust/rjustthese filters align text by default and only use half-width spaces,default and only use half-width spacesAs a fill character. Currently, the template syntax does not provide a direct parameter to specify or modify the fill character.If you need to use other characters to fill, you may need to combine other string processing methods (such as first generating a string with spaces, then usingreplaceFilter to replace spaces) or create a custom filter to do so, but this is not within the scope of these native filters.

Q2: If the specified length parameter is less than or equal to the actual length of the original string, how will these filters handle?

A2:When we arecenter/ljustorrjustThe filter provided length parameter is less than or equal to the actual length of the original string, the filter will not truncate the string or add any padding.It will directly return the original string itself. This means that these filters are mainly used for extending and aligning strings when their length is insufficient, rather than for truncating them.

Q3: Do these filters have a difference in the way they calculate the length of Chinese and English characters?

A3:AnQiCMS's template system calculates the length of strings uniformly for Chinese characters and English characters.Whether it is Chinese or English, each character is counted as a unit. For example,"你好世界"and"test"The length is inlengthThe filters will be calculated as 4. Therefore, when usingcenter/ljust/rjustWhen a filter specifies a length, it calculates the number of spaces needed to fill to reach the target width based on a unified character count. For example,"你好世界"|center:20It will still be calculated according to the length of 4 characters and filled with 16 spaces.

Related articles

AnQiCMS `ljust` and `rjust` filters how do they handle display when the string exceeds the specified length?

When building a website, we often need to finely arrange and align the text content on the page, especially when displaying lists, tables, or other areas that require a fixed layout.AnQiCMS is a powerful template engine that provides various filters to help us meet these needs, where `ljust` (left alignment) and `rjust` (right alignment) are practical tools for controlling string alignment and padding.They can make our content look more uniform and enhance the user reading experience.However, a common issue arises when using these filters

2025-11-07

How to distribute the padding spaces on both sides when the string length is odd for the AnQiCMS `center` filter?

In AnQiCMS template development, we often need to fine-tune text layout and alignment to make the page content look neater and more beautiful.At this time, filters like `center` are particularly practical.It can help us easily center the string and automatically fill in spaces on both sides.But, when you start using it, you may be curious about a detail: how does AnQiCMS distribute the spaces on both sides when the number of spaces to be filled is odd?### The basic function of the `center` filter First

2025-11-07

How to align the date and time stamp to the right to a specified length on the AnQiCMS article detail page?

On the article detail page of the website, we often hope that the publication date or update date of the article can be displayed neatly, and sometimes they need to be aligned to the right and occupy a fixed width, so that the page looks professional and beautiful.AnQiCMS provides flexible template tags and filters to help us easily meet this requirement. ### Understanding AnQiCMS Date Handling AnQiCMS typically stores dates and times in the form of timestamps (timestamps).This means calling `{{

2025-11-07

How to use the AnQiCMS `ljust` filter to align the navigation menu text to the left and fill with spaces?

AnQi CMS is an efficient and flexible content management system that provides users with rich template tags and filters, helping us easily customize all aspects of the website.Today, we will explore a practical template trick: how to use the `ljust` filter to align your navigation menu text neatly to the left and intelligently fill in spaces, thereby improving the visual consistency and user experience of the website.

2025-11-07

How to dynamically adjust the center, left, and right alignment length of text in AnQiCMS?

In website content operation, the layout and alignment of content often directly affect the user's reading experience and the efficiency of information delivery.AnQiCMS as a flexible content management system not only provides basic alignment options in the background editor, but also provides powerful filter (Filters) functions at the template level, allowing you to dynamically and finely control the alignment and display length of text.### The dynamic alignment requirements beyond the editor In the AnQiCMS backend content editor, we can of course directly set the alignment of the text to center, left, or right

2025-11-07

How to calculate the length of Chinese characters when using the AnQiCMS `center` filter to ensure centered effect?

In Anqi CMS template development, achieving accurate layout and beautiful typography is the key to improving user experience.Especially for text centering display, the `center` filter provides a very convenient feature.It can help us easily center a string within a specified length of space and fill in spaces on both sides to achieve the expected visual effect.Understand the working principle of the `center` filter This filter is designed ingeniously, it will automatically add spaces on both sides of the string according to the target total length

2025-11-07

Does AnQiCMS filter support custom non-space characters for `ljust` or `rjust` padding?

In the practice of content operation on AnQiCMS, we often need to do refined layout and design of text content on the page.For example, to maintain the alignment of tables or list items, we may use string padding functions, such as left-aligned padding (`ljust`) or right-aligned padding (`rjust`).A common question is, does AnQiCMS's template filter support using non-space characters to fill in the `ljust` or `rjust` operations?Today, let's delve deeply into this issue

2025-11-07

How to uniformly manage the alignment format of text in AnQiCMS multi-site templates?

In AnQi CMS (AnQiCMS) multi-site environment, achieving unified management of text alignment formats across different sites is the key to enhancing brand consistency, optimizing user experience, and simplifying post-maintenance.Although each site may have independent templates and content, we can completely establish a set of efficient and unified alignment management strategies by cleverly utilizing the template mechanism and front-end technology of AnQiCMS.

2025-11-07