Using mod in templates

29 views
Skip to first unread message

ameyk...@gmail.com

unread,
Nov 6, 2009, 3:38:39 PM11/6/09
to Django users
The django template language is highly restrictive - good or
bad...hmmm has its own pros and cons.

My developer faced the same issue and heres how we got it done:
You can use cycle -
<table><!--Start Table for holding the pano thumbnails-->
{% for i in jsonResponse.images%}
{% cycle '<tr><td>' '<td>' '<td>'
%}
<img width= "215"height=
"132"src="{{i.imageUrl}}">
{% cycle '</td>' '</td>' '</td></
tr>' %}
{% endfor %}
</table><!--End Table for holding the pano thumbnails--
>

And this is what you get:

<table><!--Start Table for holding the pano thumbnails-->
<tr><td>
<img width = "215" height = "132"
src="....ws.com/berry.jpg">
</td>

<td>
<img width = "215" height = "132"
src="....ws.com/berry.jpg">
</td>

<td>
<img width = "215" height = "132"
src="....ws.com/berrs.com/11yosemite-600.jpg">
</td></tr>

<tr><td>
<img width = "215" height = "132"
src="...aws.com/chit.jpg">
</td>

<td>
<img width = "215" height = "132"
src=".....11diplo-337.jpg">
</td>

<td>
<img width = "215" height = "132"
src=".....0811YOSEMITE-B.JPG">
</td></tr>
</table><!--End Table for holding the pano thumbnails--
>

I saw that many django users face this problem, hope this was of some
help.

- Amey Kanade
Engineer at EyeSee360

dfolland

unread,
Nov 6, 2009, 4:01:58 PM11/6/09
to Django users
This works if you have the exact number of images (six here). If you
have say 5, you won't have the closing </tr> tag.

On Nov 6, 2:38 pm, "ameykan...@yahoo.com" <ameykan...@gmail.com>
wrote:

Reply all
Reply to author
Forward
0 new messages