1. Go to this page and download the library: Download helsingborg-stad/blade 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/ */
$viewPaths = ['path/to/view/files'];
$cachePath = 'path/to/cache/files';
$bladeService = GlobalBladeService::getInstance($viewPaths, $cachePath);
// You can now reuse the same instance by calling:
$sameInstance = GlobalBladeService::getInstance($viewPaths, $cachePath);
$bladeService->registerDirective('datetime', function ($expression) {
return " echo with({$expression})->format('F d, Y');
$bladeService->registerComponent('foo', function ($view) {
$view->with('name', 'John Doe');
});
// The component can now be used by adding @component('foo')@endcomponent to a view file.
$bladeService->registerComponentDirective('componentname', 'directivename');
// This will register a directive that can be used by adding @directivename()@enddirectivename to a view file, and it will output the component.