PHP code example of robertkleinschuster / mosaic
1. Go to this page and download the library: Download robertkleinschuster/mosaic library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
robertkleinschuster / mosaic example snippets
$renderer->render("Hello, world");
$fragment = $renderer->fragment('<div>Hello, world</div>');
$renderer->render($fragment);
$renderer->render(function ($data) {
return "Hello, " . $data['name'];
}, ['name' => 'world']);
$items = ['item1', 'item2', 'item3'];
$renderer->render($items);
$items = ['item1', 'item2', 'item3'];
$renderer->render(function() {
yield "first\n",
yield "second\n",
yield "third\n",
});
class MyComponent implements \Mosaic\Renderable {
public function render(\Mosaic\Renderer $renderer, $data) {
yield $renderer->fragment("<div>Hello, {$data['name']}</div>");
}
}
$renderer->render(new MyComponent(), ['name' => 'world']);
#[Attribute]
class MyWrapper implements \Mosaic\RenderableAttribute {
public function render(\Mosaic\Renderer $renderer, mixed $children, mixed $data){
return $renderer->fragment(<<<HTML
<p class="wrapper">
{$renderer->render($children, $data)}
</p>
HTML
);
}
}
$renderer->render(#[MyWrapper] fn() => 'Hello world!')
$renderer->render(fn(string $name) => "Hello $name!", name: 'world')