Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#15570 closed (fixed)

{% cycle ... as foo silent %} is broken in practice

Reported by: russellm 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: UI/UX:

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.

Change History (3)

comment:1 Changed 4 years ago by russellm

Credit where it's due -- this was reported by Brian Neal

comment:2 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

In [15773]:

Fixed #15570 -- Corrected a flaw in the design of the silent flag on {% cycle %}. Thanks to Brian Neal for the report, and to Andrew and Jannis for the design consult.

comment:3 Changed 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top