<> >Then, later:
% for column in split_into_cols(my_list, COLS):
<ul class="column">
% for item in column:
display item
% endfor
</ul>
% endfor
If you want to use unordered lists, you'll furthermore need to play around with the CSS till you get the look you want. The general way to do this would be to give the lists float: left and a width in either pixels or percent, and put a div with clear:left at the bottom and/or enclose them in a container with float: left; width: 100%;. Hard to say without knowing what "look" you want. Since you said "grid" in your post, you might prefer a table.<%! from foo import split_into_cols COLS = 2 %>
<table cellspacing="0" cellpadding="0" border="0">
<tr class="b">
% for result in results:
<td class="b">
<td>
<%call expr="self.link(result)">
<img src="${result['thumbnail'] | h}" border="0">
</%call>
</td>
<td>
<%call expr="self.link(result)">${h.truncate(result['name'], length=25) | h}</%call>
</td>
</td>
% endfor
</tr>
</table>
display: block; float: left; overflow:hidden; and a fixed width and height, (or width: 49.5% for two columns) and put them into a container that is sized so they wrap the way you want. This could cause problems if your text overflows and is truncated, but I see you're already limiting the length of the text.my_list = range(21) # sample data COLS = 2 num_rows = (len(my_list) + COLS - 1) / COLS out_list = [my_list[x * COLS:(x + 1) * COLS] for x in xrange(num_rows)]Then use nested for loops (the output is a list of lists that in this case goes [[1,2],[3,4]...]) and structure the HTML however you want.
You are not logged in, either login or create an account to post comments
posted by floam at 4:17 AM on May 22