length_is Filter

Logic

Argument: n (required) – the length to compare value to.

Documentation

Returns True if the length of the value is n. Otherwise, it returns False.

This is most useful in a condition.

Variable

veggies = ['Tomatoes', 'Cucumbers', 'Peas']

Template

{% if veggies|length_is:3 %}
  <p>Looks like a trio of veggies tonight!</p>
{% endif %}

Result

<p>Looks like a trio of veggies tonight!</p>

Commentary

Maybe we are missing something, isn't using the length filter just as easy?

{% if veggies|length == 3 %}
  <p>Looks like a trio of veggies tonight!</p>
{% endif %}

Did we get something wrong? Is there a use case for the length_is filter that we should add? Please let us know.

Send Feedback

Official Documentation
This page last updated on Oct. 30, 2022, 1:21 p.m. EST