Center, left-justified, and right-justified string display by specified length

How to display a string centered, left-aligned, or right-aligned with a specified length in the Anqi CMS template?

center

ljust

rjust

Usage Instructions

centerHow to use the filter:

{{ obj|center:number }}

ljustHow to use the filter:

{{ obj|ljust:number }}

rjustHow to use the filter:

{{ obj|rjust:number }}

For example, to transformtestTo display a string centered with 20 characters, you can write it like this:

'{{ "test"|center:20 }}'
# 显示结果
'        test        '

Here is an example demonstration

centerFilter

'{{ "test"|center:3 }}'
'{{ "test"|center:19 }}'
'{{ "test"|center:20 }}'
{{ "test"|center:20|length }}
'{{ "test2"|center:19 }}'
'{{ "test2"|center:20 }}'
{{ "test2"|center:20|length }}
'{{ "你好世界"|center:20 }}'
# 显示结果
'test'
'        test       '
'        test        '
20
'       test2       '
'        test2       '
20
'        你好世界        '

ljustFilter

'{{ "test"|ljust:"2" }}'
'{{ "test"|ljust:"20" }}'
{{ "test"|ljust:"20"|length }}
'{{ "你好世界"|ljust:10 }}'
# 显示结果
'test'
'test                '
20
'你好世界      '

rjustFilter

'{{ "test"|rjust:"2" }}'
'{{ "test"|rjust:"20" }}'
{{ "test"|rjust:"20"|length }}
'{{ "你好世界"|rjust:10 }}'
# 显示结果
'test'
'                test'
20
'      你好世界'