Slots
Slots define placeholders in layouts that can be dynamically filled with templates. They are the foundation of layout composition.
---1. Basic Slot
<div data-slot="content"></div>
$tpl->slot('content', 'home');
---
2. Nested Slots
$admin = $tpl->slot('content', 'admin');
$dashboard = $admin->slot('content', 'dashboard');
Structure:
base → admin → dashboard---
3. Slot with Data Binding
$page = $tpl->slot('content', 'home');
$page->pick('title')->content('Dashboard');
---
4. Slot with Path
$tpl->slot('content', 'home', 'pages');
---
5. Slot Inside Slot
Child templates can define their own slots.
---6. Common Mistakes
❌ Missing
❌ Duplicate slot names
❌ Wrong slot name
❌ Rendering child before parent
---
data-slot in layout❌ Duplicate slot names
❌ Wrong slot name
❌ Rendering child before parent
7. Rules
- Slot name must match
data-slot - Only first match is used
- Slot replaces inner content
8. Best Practices
- Use slots for layout structure only
- Keep slot hierarchy shallow
- Avoid dynamic slot names
Slots are the backbone of layout composition.