Cycle & Include tags

56 views
Skip to first unread message

Brian Neal

unread,
Mar 7, 2011, 10:29:26 PM3/7/11
to Django users
I'm using a recent checkout of Django trunk.

If I have a template "test.html" which is this:

{{ rowcolors }}

the only way I could make cycle and include behave together is to do
this:

{% for obj in page.object_list %}
<!-- {% cycle 'odd' 'even' as rowcolors %} -->
{% include 'test.html' %}
{% endfor %}

I thought that perhaps the new "silent" keyword would eliminate the
need to HTML comment out the cycle tag:

{% for obj in page.object_list %}
{% cycle 'odd' 'even' as rowcolors silent %}
{% include 'test.html' %}
{% endfor %}

However, the very first time through the for loop, rowcolors is not
set in the included template. It works on subsequent cycles though.

Is there a way to make this work without having to HTML comment out
the cycle tag output? Admittedly it's a minor annoyance.

Thanks!

Russell Keith-Magee

unread,
Mar 8, 2011, 8:29:40 AM3/8/11
to django...@googlegroups.com

It looks like you may have discovered a problem with the silent flag
as designed. The use you present is exactly what the silent flag was
designed to address; but it appears that it doesn't actually hit that
use case.

I've just opened #15570 to track this problem, and since this is a new
feature (which will require a backwards incompatible change to fix),
it is a blocker for 1.3 final. The fix will be to make silent *always*
put the value into context, but not render a value. This is the usage
that your second sample suggests as appropriate usage.

Yours,
Russ Magee %-)

Russell Keith-Magee

unread,
Mar 8, 2011, 8:46:51 AM3/8/11
to django...@googlegroups.com

... and, FYI: Fixed in r15773.

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages