#33864: Deprecate length_is template filter in favor of length.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: length_is, length, | Triage Stage: Accepted
template, filter |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Nick Pope:
Old 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
> [https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#length-is
> 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:
>
> {{{#!django
> {# 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.
> }}}
New description:
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
[https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#length-is
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:
{{{#!django
{# 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.
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701822a6f1345-cce8f02a-46a8-4e32-9ad8-4c8274fb791e-000000%40eu-central-1.amazonses.com.