CommonPHP UI renders a View through a renderer driver. The fastest path is ViewFactory with the native PHP renderer.
Create a PHP template:
<!-- templates/pages/home.php -->
<h1><?= $e($title) ?></h1>
<p><?= $e($message) ?></p>Create an optional layout:
<!-- templates/layouts/main.php -->
<!doctype html>
<html>
<body>
<?= $content ?>
</body>
</html>use CommonPHP\UI\ViewFactory;
$ui = new ViewFactory(templatePaths: [__DIR__ . '/templates']);
$html = $ui->render(
'pages.home',
[
'title' => 'Dashboard',
'message' => 'Welcome back.',
],
'layouts.main',
);Template names can be dotted (pages.home) or path-like (pages/home.php). Dotted names are converted into directory paths by the native renderer.
use CommonPHP\UI\Component;
$ui->registerComponent(new Component('badge', 'components.badge', [
'label' => 'New',
]));Then call it inside a native PHP template:
<?= $component('badge', ['label' => 'Ready']) ?>