How to get the length of a string, array, and key-value pair in the Anqi CMS template?
length
The 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_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 }}
# 显示结果
8
Sample Demo
length
Filter
{{ "john doe"|length }}
{{ "你好世界"|length }}
# 显示结果
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 }}
{{ "你好世界"|length_is:4 }}
{{ "你好世界"|length_is:3 }}
{{ "你好世界"|length_is:5 }}
# 显示结果
True
False
True
False
False
True
False
False