Bootstrap FreeKB - Jinja - Determine the length of a string or list
Jinja - Determine the length of a string or list

Updated:   |  Jinja articles

length is a Jinja filter used to return the number of elements in a variable or list. For example, let's say you've created the following variables and lists.

empty string length = {{ '' | length }}

{% set emptylist=[] %}
empty list length = {{ emptylist | length }}

'Hello World' length = {{ 'Hello World' | length }}

{% set fruits=['apple','banana','grape','orange'] %}
fruits list length = {{ fruits | length }}

 

Something like this should be returned.

empty string length  = 0
emptylist length     = 0
'Hello World' length = 11
fruits list length   = 4

 




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 8ebf86 in the box below so that we can be sure you are a human.