Bootstrap FreeKB - Jinja - Return the first element in a list
Jinja - Return the first element in a list

Updated:   |  Jinja articles

first is a Jinja filter that can be used to return the first element in a list. Take for example the following.

{% set fruits=['banana','grapes','apples','pineapples'] %}

<br /><br />

Original List: 
{{ fruits }}

<br /><br />

First Element in List:
{{ fruits | first }}

<br /><br />

First Element in Sorted List: 
{{ fruits | sort | first }}

 

Something like this should be returned.

Original List: ['banana', 'grapes', 'apples', 'pineapples']

First Element in List: banana

First Element in Sorted List: apples

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter b2e5a7 in the box below so that we can be sure you are a human.