Extract an element from a string or array at a specified position

How to extract a string, element at a specified position in an array in Anqi CMS template?

sliceThe filter can extract elements from a string or an array at specified positions. For example, to get the 3rd to 7th elements of an array with 10 elements.

Usage Instructions

sliceHow to use the filter:

{{obj|slice:"from:to"}}

Attention must be paid to the use of 'from' and 'to'.:For example, if you want to return the 3rd to the 7th elements in the return results, you can write it like this:[1,2,3,4,5,6,7,8,9,10]For example, if you want to return the 3rd to the 7th elements, you can write it like this:

{{"1,2,3,4,5,6,7,8,9,10"|split:","|slice:"3:7"|join:","}}
# 显示结果
4,5,6,7

Here is an example demonstration

{{ simple.multiple_item_list|slice:":99"|join:"," }}
{{ simple.multiple_item_list|slice:"99:"|join:"," }}
{{ simple.multiple_item_list|slice:":3"|join:"," }}
{{ simple.multiple_item_list|slice:"3:5"|join:"," }}
{{ simple.multiple_item_list|slice:"2:"|join:"," }}
{{ simple.multiple_item_list|slice:"2:3"|join:"," }}
{{ simple.multiple_item_list|slice:"2:1"|join:"," }}
{{ simple.multiple_item_list|slice:"-1:"|join:"," }}
{{ simple.multiple_item_list|slice:":-1"|join:"," }}
{{ simple.multiple_item_list|slice:"-3:"|join:"," }}
{{ simple.multiple_item_list|slice:":-3"|join:"," }}
{{ simple.multiple_item_list|slice:"-100:"|join:"," }}
{{ simple.multiple_item_list|slice:":-100"|join:"," }}
{{ simple.multiple_item_list|slice:"-100:-1"|join:"," }}
{{ simple.multiple_item_list|slice:"-100:1"|join:"," }}
{{ simple.multiple_item_list|slice:"-100:-99"|join:"," }}
{{ simple.multiple_item_list|slice:"-100:99"|join:"," }}
{{ simple.multiple_item_list|slice:"-1:3"|join:"," }}
{{ simple.multiple_item_list|slice:"1:-3"|join:"," }}
{{ simple.multiple_item_list|slice:"-1:-3"|join:"," }}
{{ simple.multiple_item_list|slice:"-3:-1"|join:"," }}
{{ "Test"|slice:"1:3" }}
{{ "你好时间"|slice:"1:3" }}
# 显示结果
1,1,2,3,5,8,13,21,34,55

1,1,2
3,5
2,3,5,8,13,21,34,55
2

55
1,1,2,3,5,8,13,21,34
21,34,55
1,1,2,3,5,8,13
1,1,2,3,5,8,13,21,34,55

1,1,2,3,5,8,13,21,34
1

1,1,2,3,5,8,13,21,34,55

1,2,3,5,8,13

21,34
es
好世