How to get the length of a string, array, and key-value pair in Anqi CMS template?
lengthThe filter can get the length of strings, arrays, and key-value pairs.For a string, calculate the actual number of UTF-8 characters, one letter is one, and one Chinese character is also 1.If an array and key-value pair are then calculate their index count.
It can also be used.length_isTo calculate the length while comparing it with the input length value and returning a boolean indicating whether they are the same (bool).
Usage method
lengthHow to use the filter:
{{ obj|length }}
For example, if you need to returnjohn doeIf the length is, then it can be written as:
{{ "john doe"|length }}
# 显示结果
8
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