How to get the first or last value of a string or array in Anqi CMS template?
first
The filter can get the first character of the string or the first value of the array. If the original string or array is empty, nothing will be returned. If the string is Chinese, the first Chinese character is returned.
last
Filters can get the last character of a string or the last value of an array. If the original string or array is empty, nothing will be returned. If the string is Chinese, the last Chinese character is returned.
How to use
first
How to use filters:
{{ obj|first }}
last
How to use filters:
{{ obj|last }}
For example, you need to returnTest
The first character in it can be written like this:
{{ "Test"|first }} # Show result T
Sample Demo
first
Filter
{{ "Test"|first }} {{ complex.comments|first }} {{ 5|first }} {{ true|first }} {{ nothing|first }} {{ "Hello World"|first }} # Show results T <pongo2_test.comment Value> You
last
Filter
{{ "Test"|last }} {{ complex.comments|last }} {{ 5|last }} {{ true|last }} {{ nothing|last }} {{ "Hello World"|last }} # Show results t <pongo2_test.comment Value>