1. Go to this page and download the library: Download craftile/laravel 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/ */
craftile / laravel example snippets
namespace App\Blocks;
use Craftile\Core\Contracts\BlockInterface;
use Craftile\Core\Data\Property\Text;
use Craftile\Core\Data\Property\Boolean;
class Hero implements BlockInterface
{
public static function getType(): string
{
return 'hero';
}
public static function getLabel(): string
{
return 'Hero Section';
}
public static function properties(): array
{
return [
Text::make('title', 'Title')->default('Welcome'),
Text::make('subtitle', 'Subtitle'),
Boolean::make('showButton', 'Show Button')->default(true),
];
}
protected static array $accepts = ['button', 'text']; // Optional: specify accepted child types
public function render(): mixed
{
return view('blocks.hero');
}
}
// In AppServiceProvider or dedicated BlockServiceProvider
use Craftile\Laravel\Facades\Craftile;
public function boot()
{
Craftile::registerBlock(Hero::class);
}
Route::get('/', function () {
return view('pages.homepage'); // Will automatically compile the JSON template
});
// In your block class
protected static array $accepts = ['*']; // Accept any child type
// or
protected static array $accepts = ['button', 'text']; // Accept specific types
// In your block template
@children {{-- Renders all child blocks --}}
'directives' => [
'craftileBlock' => 'block', // @block instead of @craftileBlock
'craftileContent' => 'content', // @content instead of @craftileContent
],