Oh, sorry, I misread your RHTML. In that case, I'd use Steve Ross's
solution.
Doug wrote:
> Doing this results in HTML that looks something like:
>
> <tr>
> <td>
> ...admin...
> </td
> </tr>
> <td>
> ...admin...
> </td>
> <tr>
> <td>
> ...admin...
> </td
> </tr>
>
> Every other <td> will fall outside of its <tr> block. Any ideas?
>
> On Nov 30, 10:20 pm, Nathan Weizenbaum <[EMAIL PROTECTED]> wrote:
>
>> Well, a direct translation of your RHTML would be
>>
>> @administrator.each_with_index do |administrator, i|
>> = "<tr>" if i % 2 == 0
>> %td
>> = administrator.full_name
>> %br/
>> = mail_to administrator.email
>> = "</tr>" if i % 2 == 0
>>
>> which works, but doesn't indent within the <tr>s. A nicer solution would
>> be to define a helper:
>>
>> def tr_if(cond, &block)
>> if cond
>> open("tr", &block)
>> else
>> block.call
>> end
>> end
>>
>> Then you could make your template
>>
>> @administrator.each_with_index do |administrator, i|
>> - tr_if i % 2 == 0 do
>> %td
>> = administrator.full_name
>> %br/
>> = mail_to administrator.email
>>
>> - Nathan
>>
>> Doug wrote:
>>
>>> With a list of ActiveRecord objects, is there a way in HAML to output
>>> one cell per iterated object, and two per table row? Something
>>> equivalent to this in RHTML:
>>>
>>> <% @administrator.each_with_index do |administrator, i| %>
>>> <%= "<tr>" if i % 2 == 0 %>
>>> <td>
>>> <%= administrator.full_name %>
>>> <br/>
>>> <%= mail_to administrator.email %>
>>> </td>
>>> <%= "</tr>" unless i % 2 == 0 %>
>>>
>>> I've fought with this for a while with no luck. Any input would be
>>> greatly appreciated!
>>>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---