How to center the string, left, and right in the Anqi CMS template in the specified length format?
center
Filters 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.
ljust
The 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. .
rjust
The 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
center
How to use filters:
{{ obj|center:number }}
ljust
How to use filters:
{{ obj|ljust:number }}
rjust
How to use filters:
{{ obj|rjust:number }}
For exampletest
If it is centered at 20 characters, you can write it like this:
'{{ "test"|center:20 }}' # Show results ' test '
Sample Demo
center
Filter
'{{ "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 '
ljust
Filter
'{{ "test"|ljust:"2" }}' '{{ "test"|ljust:"20" }}' {{ "test"|ljust:"20"|length }} '{{ "Hello World"|ljust:10 }}' # Show results 'test' 'test ' 20 'Hello World'
rjust
Filter
'{{ "test"|rjust:"2" }}' '{{ "test"|rjust:"20" }}' {{ "test"|rjust:"20"|length }} '{{ "Hello World"|rjust:10 }}' # Show results ' test' 20 ' Hello World'