Get the length of string, array, key-value pairs

How to get the length of strings, arrays, and key-value pairs in Anqi CMS template?

lengthFilters 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_isWhile calculating the length, compare it with the input length value and return whether the same Boolean value (bool).

How to use

lengthHow to use filters:

{{ obj|length }}

For example, you need to returnjohn doeThe length can be written like this:

{{ "john doe"|length }}
# Show results
8

Sample Demo

lengthFilter

{{ "john doe"|length }}
{{ "Hello world"|length }}
# Show results
8
4

length_isFilter

{{ "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