On Oct 11, 7:58 am, jhf555 <[EMAIL PROTECTED]> wrote:
> I have an array and I want to use Django templating to display each
> item in a table, grouped by 3 per row.
> For example, if i have
>   arr = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
> Then I'd want it to show up as
> <table>
>   <tr><td>a</td><td>b</td><td>c</td></tr>
>   <tr><td>d</td><td>e</td><td>f</td></tr>
>   <tr><td>g</td><td>h</td><td>i</td></tr>
>   <tr><td>j</td><td></td><td></td></tr>
> </table>
>
> In general, the array could be any length, and it's possible I'd want
> to do 4 or 5 per row, not necessarily 3.
>
> What's the easiest way to do this?  Thanks a bunch.

Use a for loop and the 'divisibleby' filter.

<table>
{% for letter in arr %}
{% if forloop.counter|divisibleby:"3" %}<tr>{% endif %}
<td>{{ letter }}</td>
{% if forloop.counter|divisibleby:"3" %}</tr>{% endif %}
{% endfor %}
</table>

--
DR.
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to