How to get the first or last value of a string or array in the Anqi CMS template?
first
The filter can obtain the first character of a string or the first value of an array. If the original string or array is empty, nothing is returned. If the string is Chinese, the first character is returned.
last
The filter can obtain the last character of a string or the last value of an array.If the original string or array is empty, nothing is returned.If the string is Chinese, return the last Chinese character.
Usage Instructions
first
How to use the filter:
{{ obj|first }}
last
How to use the filter:
{{ obj|last }}
For example, if you need to returnTest
the first character of:
{{ "Test"|first }}
# 显示结果
T
Here is an example demonstration
first
Filter
{{ "Test"|first }}
{{ complex.comments|first }}
{{ 5|first }}
{{ true|first }}
{{ nothing|first }}
{{ "你好世界"|first }}
# 显示结果
T
<pongo2_test.comment Value>
你
last
Filter
{{ "Test"|last }}
{{ complex.comments|last }}
{{ 5|last }}
{{ true|last }}
{{ nothing|last }}
{{ "你好世界"|last }}
# 显示结果
t
<pongo2_test.comment Value>
界