System\Classes\ViewComponent
Overview
ViewComponent is a lightweight component that renders from a view file.
Supports inline rendering and slot-based content capture:
<?= UiFactory::button(label: 'Save') ?>
<?php UiFactory::card(title: 'Hey')->slot() ?>
<p>Content</p>
<?php UiFactory::end() ?>
Implements
- Stringable
Protected Properties
protected string $name
name of the component
protected array $props
props passed to the component view
protected array $attributes
attributes passed through to the AttributeBag
protected array $slots
slots captured content keyed by slot name
protected string|null $currentSlot
currentSlot being captured
protected static array $stack
stack of active components for nesting support
Public Methods
public __call()
public __call($method, $args): static
__call supports fluent API for setting props
public __construct()
public __construct($name, $props = [], $attributes = []): void
public __toString()
public __toString(): string
__toString renders the component inline
public static captureSlot()
public static captureSlot($name): void
captureSlot switches to a new named slot, closing the previous one
public static endComponent()
public static endComponent(): void
endComponent captures the final slot and renders the component
public slot()
public slot($name = 'default'): void
slot starts capturing content for a named slot
Protected Methods
protected render()
protected render(): string
render the component view file and return HTML