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

How to get the length of a string, array, and key-value pair in the Anqi CMS template?

lengthThe filter can obtain the length of strings, arrays, and key-value pairs.For strings, calculate the actual character count of its utf8, with one letter or one Chinese character counting as one.Calculate the number of indices for arrays and key-value pairs.

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 }}
# 显示结果
8

Sample Demo

lengthFilter

{{ "john doe"|length }}
{{ "你好世界"|length }}
# 显示结果
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 }}
{{ "你好世界"|length_is:4 }}
{{ "你好世界"|length_is:3 }}
{{ "你好世界"|length_is:5 }}
# 显示结果
True
False
True
False
False
True
False
False