Thanks, I've used the method that you have explained. I've had a read
of the ticket on this and there is now a patch which I've used so I
can pass a parameter into the cycle tag to tell it now to write an
output.



On Jun 7, 2:38 am, Russell Keith-Magee <russ...@keith-magee.com>
wrote:
> On Sun, Jun 6, 2010 at 8:05 AM, cootetom <coote...@gmail.com> wrote:
> > Hi all,
>
> > I've decided to upgrade to 1.2 but have hit a stumbling block with the
> > cycle tag. The release notes 
> > herehttp://docs.djangoproject.com/en/dev/releases/1.2/#stateful-template-...
> > say that because of the new thread safe template renderer that
> > including another template whilst inside a loop means the included
> > template doesn't know the state of the cycle tag.
>
> > So I understand why this was done but I'm also trying to find a way to
> > now make my templates work. I always put the HTML for table rows in
> > their own template and then include them in the page template inside
> > loops. This is because if I then need to create just a single table
> > row then I have the template that does that. However I can't figure
> > out now how to inform the included template which row class names to
> > use as I've always used the cycle tag in the past.
>
> > Has anyone else come up with a pattern to solve this?
>
> Sure - Move the cycle tag outside the include.
>
> Included templates inherit the context from the template that does the
> including, so if you define the cycle tag outside the include using
> the "as X" assignment syntax, you can use that variable in your
> template. So, if you previously had:
>
> {% for x in values %}
>    {% include "subtemplate.html" %}
> {% endfor %}
>
> with subtemplate.html of:
>
> {% cycle 'a' 'b' %}
>
> you can replace this with:
>
> {% for x in values %}
>     <!-- {% cycle 'a' 'b' as row %} -->
>     {% include "subtemplate.html" %}
> {% endfor %}
>
> with a subtemplate.html of:
> {{ row }}
>
> The one slight complication is that {% cycle 'a' 'b' as row %} outputs
> the value of the cycle. This means you'll need to find some way to
> hide this output (such as putting it in a HTML comment as in the
> example I have given). This is a known issue (#13567), but it's not
> trivial to fix because there are some backwards-compatibility issues
> that need to be addressed.
>
> Yours,
> Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to