This PHP package provides a server-side compiler to render custom HTML components. This package is inspired by the BladeX package for Laravel. From the new 1.0.0 version this package uses the Laravel Blade Compiler. You can now use all the functionalities (non-anonymous components are not supported yet) provided by Laravel Blade Components.
You can write this:
<my-alert type="error" message="I'm an Alert" />
And the output will be:
<div class="alert error">I'm an alert</div>
You can place the content of that alert in a simple Blade view that needs to be registered before using the my-alert component:
<div class="alert {{ $type }}">
{{ $message }}
</div>
composer require netflie/componentes
Before writting your first component you have to setup the view filesystem, the place where you component templates will be stored:
<?php declare(strict_types=1);
namespace Foo\Bar;
use Netflie\Componentes\Componentes;
$viewPath = realpath(__DIR__ . '/views'); // your project views folder
$componentes = Componentes::create($viewPath);
Write the content of you component in a Blade template and store it in your project view components folder:
{{-- your_project/views/components/alert.blade.php --}}
<div class="alert {{ $type }}">
{{ $message }}
</div>
All anonymous components are automatically discovered within the your_project/views/components
directory.
And now you can use your custom HTML elements in your views:
<h1>My view</h1>
<x-alert type="error" message="I'm an Alert" />
You need compile the HTML to render the HTML elements registered. This HTML code can come already precompilated by a framework or be read directly from an html file:
<?php
namespace Foo\Bar;
$input_html = '<html>'
.'My webpage code precompiled by my own framework'
.'<x-alert/>'
.'</html>';
$ouput_html = $componentes->render($input_html);
Check the Laravel Blade Components documentation to full functionalities.
composer test
- Class based component