#33864: Deprecate length_is template filter in favor of length.
-------------------------------------+-------------------------------------
               Reporter:  Nick Pope  |          Owner:  Nick Pope
                   Type:             |         Status:  assigned
  Cleanup/optimization               |
              Component:  Template   |        Version:  dev
  system                             |       Keywords:  length_is, length,
               Severity:  Normal     |  template, filter
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33864>
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/0107018227ede06f-dcde4643-bdee-4df6-996c-0b38c33f04dd-000000%40eu-central-1.amazonses.com.

Reply via email to