On 5 jan, 23:39, "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 %}
This just won't work > {% for art in my_art_list %} > {% if count%3 = 0 %} idem > <tr> > {% endif %} > <td> > <img src="{{ art.img_path }}" alt="{{ > art.title }}" /> > </td> > {% if count%3 = 2 %} idem > </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. The first one being it's not valid. > Is there a way to have tracking variables in the > template code? Read the documentation for the {% for %} template tag - it sets a {{ forloop.counter }} variable. http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for You may also want to have a look at the {% cycle %} tag (same page as above), and / or be interested in the "partition" filters on djangosnippets: http://www.djangosnippets.org/snippets/6/ http://www.djangosnippets.org/snippets/401/ > I was under the impression that the {% %} tags were > just straight Python code I don't know where you got this impression from. Oh, wait : you didn't read the doc, did you ? > and would execute as such, but apparently my > understanding is a little less than adequate. I do confirm !-) > Please help me sort this out... Well... What about reading the online documentation first ?-) HTH --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---