#10975 closed (wontfix)
Accessing derived block doesn't work within ifequal tag
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Uncategorized | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Here is the http://dpaste.com/40134/ code of what I mean. Essentially using a block in a derived template that was specified from within an ifequal tag in the parent template doesn't work.
Change History (6)
comment:1 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 16 years ago
IMHO, this is not true: a block *can* be defined in a if
construct, but not in ifequal
, ifnotequal
.
comment:3 by , 16 years ago
Moreover, if it's design decision (IMO, an arguable one:), then there should be a template syntax error or something. Instead everything works almost fine, but the block cannot be redefined. Users may spend lots of time before searching the tickets database just to read "hey, it's meant to be so".
Why this design is such and not different? I see no clean solution for my design. I have a generic template with few if
/ifequal
statements, and the other template extending the first one and redefining some blocks. I know the redefining makes sense, I know that the original blocks would be displayed (and yes, they are displayed). If am not allowed to redefine them (e.g. redefine labels, snippets, small widgets) I'm forced to pass them in the rendering context, thus the context will have to contain some HTML snippets -- which I personally treat a poor design.
I this ticket is to remain closed, can you, please, tell how I (and other users:) should construct their templates?
comment:4 by , 15 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
you can paste this at the end of your settings.py
from django.template.defaulttags import IfEqualNode def get_nodes_by_type(self, nodetype): nodes = [] if isinstance(self, nodetype): nodes.append(self) nodes.extend(self.nodelist_true.get_nodes_by_type(nodetype)) nodes.extend(self.nodelist_false.get_nodes_by_type(nodetype)) return nodes IfEqualNode.get_nodes_by_type = get_nodes_by_type
IMHO, this should be reopened and fixed.
Users may want to display things differently according to a condition,
e.g. I would want to have that in a base template:
{% ifnotequal setting u'inverted'%} {% block a %}{% endblock %} {% block b %}{% endblock %} {% else %} {% block b %}{% endblock %} {% block a %}{% endblock %} {% endifnotequal %}
comment:5 by , 15 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
Repeating myself:
"A block cannot be defined conditionally within any sort of "if" construct, and this is by design; the structure of the template is the structure of the template."
If you disagree, please take it to the django-developers list.
A block cannot be defined conditionally within any sort of "if" construct, and this is by design; the structure of the template is the structure of the template.