visualbuilder / email-templates

Email Template Editor for Filament
GNU General Public License v3.0
74 stars 19 forks source link

How to handle loops in template? #25

Closed lutek closed 3 weeks ago

lutek commented 3 weeks ago

I would like to see some example/hint with Order items in table row.

cannycookie commented 3 weeks ago

Just create a blade view something like this:-

<table>
@foreach($order->items as $item)
<tr>
<td>{{$item->name}}</td>
<td>{{$item->qty}}</td>
...
</tr>
@endforeach
</table>

Then in your order model

public function getItemsTableAttribute(): string
{
    return view('components.order_table', ['order' => $this])->render();
}

So then in your email template you can use:-

##order.items_table##