Center the string, left, and right in the specified length format

How to center the string, left, and right in the Anqi CMS template in the specified length format?

centerFilters can center strings in specified length format. If the string length is greater than the specified length, it will be displayed according to the actual length of the string. If the string length is less than the specified length, the same number of spaces will be added to both sides of the string to achieve centering. If the number of spaces that need to be supplemented is singular, the spaces on the right will be assigned one less than the left.

ljustThe filter can display the string to the left in the specified length format. If the string length is greater than the specified length, it is displayed according to the actual length of the string. If the string length is less than the specified length, spaces will be added to the right of the string. .

rjustThe filter can display the string to the right in the specified length format. If the string length is greater than the specified length, it is displayed according to the actual length of the string. If the string length is less than the specified length, spaces will be added to the left of the string.

How to use

centerHow to use filters:

{{ obj|center:number }}

ljustHow to use filters:

{{ obj|ljust:number }}

rjustHow to use filters:

{{ obj|rjust:number }}

For exampletestIf it is centered at 20 characters, you can write it like this:

'{{ "test"|center:20 }}'
# Show results
' test '

Sample Demo

centerFilter

'{{ "test"|center:3 }}'
'{{ "test"|center:19 }}'
'{{ "test"|center:20 }}'
'{{ "test"|center:20 }}'
'{{ "test"|center:20|length }}'
'{{ "test"|center:20 }}'
'{{ "test"|center:20 }}'
'{{ "test"|center:20 }}'
'{{ "test"|center:20 }}'
'{{ "test"|center:20 }}'
'{{ "Hello World"|center:20 }}'
'{{ "Hello World"|center:20 }}'
# Show results
'' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '
' test '< '
20
' Hello world '

ljustFilter

'{{ "test"|ljust:"2" }}'
'{{ "test"|ljust:"20" }}'
{{ "test"|ljust:"20"|length }}
'{{ "Hello World"|ljust:10 }}'
# Show results
'test'
'test '
20
'Hello World'

rjustFilter

'{{ "test"|rjust:"2" }}'
'{{ "test"|rjust:"20" }}'
{{ "test"|rjust:"20"|length }}
'{{ "Hello World"|rjust:10 }}'
# Show results
' test'
20
' Hello World'