oscurlo / component-renderer
Lightweight PHP library for rendering reusable HTML components — inspired by JSX, built on DOMDocument, no build step required.
v1.2.0
2026-05-04 21:33 UTC
Requires
- php: >=8.0
- ext-dom: *
- ext-libxml: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.65
- phpunit/phpunit: ^11.4
README
A lightweight PHP library for rendering reusable HTML components — inspired by JSX, built on DOMDocument, no build step required.
Documentation
Quick start
composer require oscurlo/component-renderer
use Oscurlo\ComponentRenderer\ComponentRenderer; $renderer = new ComponentRenderer([ 'MyApp\\Components' => ['Button', 'Card'], ]); $renderer->render('<Card title="Hello"><Button>Click me</Button></Card>');
Examples
| # | What it shows |
|---|---|
| example1.php | Multiple components — functions, namespaces, class methods |
| example2.php | Output buffering with start() / end() |
| example3.php | Templates with variables via Component::template() |
| example4.php | Static API with Component::render() |
| example5.php | PropsCaster — type-safe props (bool, int, array…) |
| example6.php | Nested components + Bootstrap::accordion inside a card |
Requirements
- PHP >= 8.0
- ext-dom
- ext-libxml
