Try:

%table
   - (1..6).to_a.in_groups_of(3) do |row|
     %tr
     - row.each do |col|
       %td= col

I haven't actually *tried* this, but it seems it should work.


On Sep 6, 2009, at 4:57 PM, Tim W wrote:

>
> How does one do this in Haml?
>
> Say I have an array [1,2,3,4,5,6] and I want a table like...
>
> <table>
>  <tr>
>    <td>1</td>
>    <td>2</td>
>    <td>3</td>
>  </tr>
>  <tr>
>    <td>4</td>
>    <td>5</td>
>    <td>6</td>
>  </tr>
> </table>
>
> I have done it may times, but never in haml..
>
> %table
>  - [1,2,3,4,5,6].each_with_index do |n,i|
>    - if i%3 == 0
>      %tr
>    %td= n
>
> This gives a result of...
>
>                      <table>
>                        <tr></tr>
>                        <td>1</td>
>                        <td>2</td>
>                        <td>3</td>
>
>                        <tr></tr>
>                        <td>4</td>
>                        <td>5</td>
>                        <td>6</td>
>                      </table>
>
> How do I get the tr to wrap the 3 td's?
>
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to haml@googlegroups.com
To unsubscribe from this group, send email to haml+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to