# slice

Source: https://zotonic.com/docs/1820/slice

URI: https://zotonic.com/id/1820

Language: en



Perform array-slice operations on a list or string.

If the argument is a binary then it is handles as an UTF-8 encoded string.

Given a list `[1,2,3,4,5,6,7,8,9,0]`

Get all elements from element M to element N:

```django
{{ list|slice:[3,7] }} -> [3,4,5,6,7]
{{ list|slice:[3,-3] }} -> [3,4,5,6,7]
{{ list|slice:[-7,-3] }} -> [4,5,6,7]
{{ list|slice:[-7,7] }} -> [4,5,6,7]
```

Get all elements except the first N:

```django
{{ list|slice:[3,] }} -> [3,4,5,6,7,8,9,0]
{{ list|slice:[-7,] }} -> [4,5,6,7,8,9,0]
```

Get all elements up to element N:

```django
{{ list|slice:[,3] }} -> [1,2,3]
{{ list|slice:[3] }} -> [1,2,3]
```

Get all elements except the last N:

```django
{{ list|slice:[,-3] }} -> [1,2,3,4,5,6,7]
{{ list|slice:[-3] }} -> [1,2,3,4,5,6,7]
```

If the slice start is after the slice end then `[]` is returned:

```django
{{ list|slice:[2,1] }} -> []
```

An empty slice returns the whole input:

```django
{{ list|slice:[,] }} -> [1,2,3,4,5,6,7,8,9,0]
```

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1820?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1820?language=en>)
