Opened 2 years ago
Last modified 14 months ago
#33864 closed Cleanup/optimization
Deprecate length_is template filter in favor of length. — at Initial Version
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
The length_is
template filter is a vestige from the days of the {% ifequal %}
and {% ifnotequal %}
days 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.