Includes
Includes allow injecting reusable components into existing DOM elements.
---1. Basic Include
$tpl->include('#header', 'header');
---
2. Include with Data
$header = $tpl->include('#header', 'header');
$header->pick('username')->content('Tamil');
---
3. Include with Path
$tpl->include('#header', 'header', 'components');
---
4. Include Inside Loop
$item = $tpl->addLoopItem('users');
$card = $item->include('#card', 'user-card');
$card->pick('name')->content('John');
---
5. Include Inside Slot
Works seamlessly with nested layouts.
---6. Selector Rules
- Must match exactly one element
#idis recommended
7. Common Mistakes
❌ Selector matches multiple elements
❌ Selector not found
❌ Using generic selectors (.class)
❌ Reusing same include target
---
❌ Selector not found
❌ Using generic selectors (.class)
❌ Reusing same include target
8. Best Practices
- Use IDs for include targets
- Keep includes small and reusable
- Avoid deep include nesting
Includes act like reusable components.