#15570 closed (fixed)
{% cycle ... as foo silent %} is broken in practice
Reported by: | Russell Keith-Magee | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.3-beta |
Severity: | Keywords: | blocker, regression | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
r14439 introduced the 'silent' flag as a way to define a {% cycle %} without actually generating template content. This was done to address #13567.
In addition to the use case given in the ticket, one of the reasons for introducing this flag was to support the use of cycles in included subtemplates; for example:
{% for obj in page.object_list %} {% cycle 'odd' 'even' as rowcolors %} {% include 'test.html' %} {% endfor %}
In this case, we want to define the cycle as part of the loop, but use the cycle value in the subtemplate. The subtemplate can't reference {% cycle rowcolors %} because the subtemplate parser doesn't have access to the parser context of the parent template. Therefore, the subtemplate needs to use {{ rowcolors }}.
However, the implementation of the silent flag means that there is no way to define a cycle in the parent template and have it displayed in the included subtemplate *without* rendering it in the parent template. The current implementation only renders the tag silent on first usage, not subsequent uses.
This should be addressed. 'silent' should render the cycle tag silent on every use; if you define a cycle as silent, you display the cycle value by rendering the variable to which it has been bound.
Credit where it's due -- this was reported by Brian Neal