Opened 2 years ago
Last modified 15 months ago
#33864 closed Cleanup/optimization
Deprecate length_is template filter in favor of length. — at Version 3
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 )
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 (3)
comment:1 by , 2 years ago
Has patch: | set |
---|
comment:2 by , 2 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 2 years ago
Description: | modified (diff) |
---|
PR