Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Template Filter - length_is


Example

Check if there are 3 items in the list:

<h1>{{ fruits|length_is:3 }}</h1>
Run Example »

Definition and Usage

The length_is filter returns True if the length of the object is the same as the specified number.

This can be useful when you are dealing with if statements:

Example

Write "Hello" if firstname has 5 characters:

{% if firstname|length_is:5 %}
  <h1>Hello</h1>
{% endif %}
Run Example »

Syntax

{{ value|length_is:len }}

Template filters are defined by using a pipe | character followed by the name of the filter.

Arguments are defined by using a colon : character followed by the argument value.


Arguments

Value Description
len Required. A number to check if the object's length is the same as.