#35790: Deprecate content outside of {% block %} tags when {% extends %} is used
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Yogya
Type: | Chugh
Cleanup/optimization | Status: assigned
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Chris Adams):
Hi folks. I'm reviewing this ticket with [Tom
Hall](
https://github.com/[]tomhall2020), and there's a couple of questions
this brings up if you switch to raising the warning when there is a text
node outside of a block.
When we take the example below, it's reasonable that you get a warning,
and helpful to see why text `<title>Chicken egg</title>` is being silently
ignored. No problems here.
{{{
{% extends 'egg.html' %}
<title>Chicken egg</title>
{% block yolk %}
yellow
{% endblock yolk %}
}}}
There's a few other cases though.
What about where code is *not* really intended to be displayed after the
template has been rendered?
As Carlton suggested, any code like this would now be getting deprecation
errors.
{{{
{% extends 'egg.html' %}
<!-- commented out code -->
<!-- <title>Chicken egg</title> -->
{% block yolk %}
yellow
{% endblock yolk %}
}}}
Also, because we're still allowing custom tags outside a block, this would
sail through without any deprecation errors or clue to why the text in
`{{ chicken_egg_title }}`isn't appearing, because there's no real way to
discriminate between allowed and disallowed tags:
{{{
{% extends 'egg.html' %}
{{ chicken_egg_title }}
{% block yolk %}
yellow
{% endblock yolk %}
}}}
Is this the intention?
If it isn't, I wonder if it might make sense to have this as part of the
check framework, that you can switch on, rather than either forcing a
change.
Django extensions has something conceptually similar, with their
[validate_templates management command](
https://django-
extensions.readthedocs.io/en/latest/validate_templates.html). Would this
be an alternative worth considering instead?
--
Ticket URL: <
https://code.djangoproject.com/ticket/35790#comment:13>