Yep, reading the documentation helps ;). But here's how your code should look:
<table> {% for art in my_art_list %} {% cycle '<tr>' '' '' %} <td> <img src="{{ art.img_path }}" alt="{{ art.title }}" /> </td> {% cylce '</tr>' '' '' %} {% empty %} <p>You have no art pieces to view. Would you like to add some? </p> {% endfor %} </table> Assuming you are using a version of django that has support for the for...empty tag, I'm not sure when that came about. But the cycle tag is what you want. On Jan 5, 4:39 pm, "django_fo...@codechimp.net" <codech...@gmail.com> wrote: > I have a pretty simple template that needs to print some data in a > bunch of table rows. I have done something like this: > > <table> > {% if my_art_list %} > {% count = 0 %} > {% for art in my_art_list %} > {% if count%3 = 0 %} > <tr> > {% endif %} > <td> > <img src="{{ art.img_path }}" alt="{{ > art.title }}" /> > </td> > {% if count%3 = 2 %} > </tr> > {% endif %} > {% endfor %} > </tr> > {% else %} > <p>You have no art pieces to view. Would you like to add some?</p> > {% endif %} > </table> > > However, as you probably suspect, the "count" variables cause all > sorts of trouble. Is there a way to have tracking variables in the > template code? I was under the impression that the {% %} tags were > just straight Python code and would execute as such, but apparently my > understanding is a little less than adequate. > > Please help me sort this out... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~----------~----~----~----~------~----~------~--~---