Scaffolding
When a page is rendered, each component is told where it sits on the page. This is stored in the scaffolding property of the ActiveComponent base class, and data() merges it into the view's variables, so a view can use $firstOfType directly.
| Key | Meaning |
|---|---|
index |
Position among all the page's components, counting from 0 |
indexInSlot |
Position within its slot, from 0 |
firstInSlot, lastInSlot |
First or last component in its slot |
firstOfType, lastOfType |
First or last of a run of components of the same type |
indexInTypeGroup |
Position within that run, from 0 |
firstInSlot and lastInSlot are only set when they are true, so use $firstInSlot ?? false in views.
firstOfType and lastOfType are useful for grids and similar layouts, where the first and last item of a run need extra markup:
@if($firstOfType)<div class="grid grid-cols-3 gap-4">@endif
<div class="card">{{ $title }}</div>
@if($lastOfType)</div>@endif
Before this is added, the renderer calls each component's setupForPage($request, $page, $config). The default stores the block's own settings as the starting scaffolding. Override it to prepare data for the page; return a falsy value to leave the component off the page.