Opened 2 years ago

Closed 2 years ago

Last modified 14 months ago

#33864 closed Cleanup/optimization (fixed)

Deprecate length_is template filter in favor of length.

Reported by: Nick Pope Owned by: Nick Pope
Component: Template system Version: dev
Severity: Normal Keywords: length_is, length, template, filter
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Nick Pope)

The length_is template filter is a vestige from the days of the {% ifequal %} and {% ifnotequal %} tags before {% if %} arrived with support for comparison with operators. Even the example in the documentation (see here) is poor: {{ value|length_is:"4" }} will only return one of three possible values - True, False, or "", the empty string being for errors in the provided values.

It seems to me that it would be better to encourage use of the length template filter with the {% if %} template tag which can provide more flexibility:

{# Before: #}
{% if value|length_is:"4" %}...{% endif %}
{{ value|length_is:"4" }} ← This is of dubious use given the restricted set of possible output values.

{# After: #}
{% if value|length == 4 %}...{% endif %}
{% if value|length == 4 %}True{% else %}False{% endif %} ← Much clearer but also allows customising the output values.

Change History (6)

comment:1 by Nick Pope, 2 years ago

Has patch: set

comment:2 by Mariusz Felisiak, 2 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Nick Pope, 2 years ago

Description: modified (diff)

comment:4 by Mariusz Felisiak, 2 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 4d4bf55:

Fixed #33864 -- Deprecated length_is template filter.

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 14 months ago

In 14ef92f:

Refs #33864 -- Removed length_is template filter per deprecation timeline.

Note: See TracTickets for help on using tickets.
Back to Top