Get the length of a string, array, or key-value pair

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

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 1.Calculate the index count of arrays and key-value pairs.

It can also be used.length_isTo calculate the length while comparing it with the input length value and returning a boolean value (bool) indicating whether they are the same.

Usage Instructions

lengthHow to use the filter:

{{ obj|length }}

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

{{ "john doe"|length }}
# 显示结果
8

Here is an example demonstration

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