caiquebispo / blade-slim
Pacote para usar Blade (Laravel) no Slim Framework
Requires
- php: ^8.4
- illuminate/filesystem: ^12.0
- illuminate/view: ^12.0
README
Integration of Blade Template Engine with Slim Framework
A package that seamlessly integrates Laravel’s Blade templating engine with the Slim Framework, providing a smooth development experience with full Blade features in Slim applications.
Installation
Install via Composer:
composer require caiquebispo/blade-slim
Quick Setup
Configure Blade in your Slim application:
use BladeSlim\Blade; use Slim\Factory\AppFactory; $app = AppFactory::create(); // Blade Configuration $blade = new Blade( __DIR__ . '/../resources/views', // Views directory __DIR__ . '/../storage/cache', // Cache directory $app->getResponseFactory()->createResponse() // Response prototype );
Create your first view in resources/views/home.blade.php
and make sure the storage/cache
folder is writable:
<!DOCTYPE html> <html> <head> <title>{{ $title }}</title> </head> <body> <h1>Welcome to {{ $appName }}!</h1> </body> </html>
Use it in a route:
$app->get('/', function () { return view('home', [ 'title' => 'Home Page', 'appName' => 'My Slim App' ]); });
Key Features
Global view()
Function
Automatically returns a ready PSR-7 response.
Supports data, status codes, and headers:
return view('error', ['message' => 'Not Found'], 404);
Full Blade Support
- Template inheritance (
@extends
) - Sections (
@section
,@yield
) - Components (
@component
) - Custom directives
- Sub-view inclusion (
@include
)
Flexible Configuration
- Multiple view paths
- Optional caching
- Integration with Slim's DI container
Advanced Usage
Custom Directives
$blade->getFactory()->directive('datetime', function ($expression) { return "<?php echo ($expression)->format('d/m/Y H:i'); ?>"; });
Contributing
Contributions are welcome! Follow these steps:
- Fork the project
- Create your branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
📄 License
Distributed under the MIT License. See LICENSE
for more information.
📧 Contact
Caique Bispo - caiquebispodanet86@gmail.com
Project Link: https://github.com/caiquebispo/blade-slim