How to get the length of strings, arrays, and key-value pairs in Anqi CMS templates?
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 1.Calculate the index count of arrays and key-value pairs.
It can also be used.length_is
To 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
length
How to use the filter:
{{ obj|length }}
For example, if you need to returnjohn doe
The length can be written like this:
{{ "john doe"|length }}
# 显示结果
8
Here is an example demonstration
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