How to get the length of strings, arrays, and key-value pairs in Anqi CMS template?
length
Filters can get the length of strings, arrays, and key-value pairs. For a string, the number of utf8 actual characters is calculated, one letter is one, and one Chinese character is also one. Array and key-value pairs calculate their index number.
Can also be usedlength_is
While calculating the length, compare it with the input length value and return whether the same Boolean value (bool).
How to use
length
How to use filters:
{{ obj|length }}
For example, you need to returnjohn doe
The length can be written like this:
{{ "john doe"|length }} # Show results 8
Sample Demo
length
Filter
{{ "john doe"|length }} {{ "Hello world"|length }} # Show results 8 4
length_is
Filter
{{ "john doe"|length_is:8 }} {{ "john doe"|length_is:10 }} {{ "john doe"|length_is:"8" }} {{ "john doe"|length_is:"10" }} {{ 5|length_is:1 }} {{ "hello world"|length_is:4 }} {{ "hello world"|length_is:3 }} {{ "hello world"|length_is:5 }} # Display results True False True False True False False False