Pros:
Str, Html, or Form helpers via Plates extensions).Cons:
@cache directives or compiled template caching (mitigated via Laravel’s view facade or custom caching layer).{{ $var|e }}), unlike Blade’s implicit escaping (addressable via Plates extensions or middleware).View facade or wrapping Plates’ Engine in a service provider.// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton('plates.engine', function () {
return new League\Plates\Engine('resources/views');
});
}
View::make() to use Plates:
View::macro('make', function ($path, $data = [], $mergeData = []) {
return app('plates.engine')->render($path, $data);
});
// App\Http\Middleware\InjectPlatesData.php
public function handle($request, Closure $next)
{
app('plates.engine')->setData(['csrf_token' => csrf_token()]);
return $next($request);
}
get() → fetch(), end() → stop()) may require refactoring existing Blade templates.@stack, @include) to Plates equivalents (e.g., {{ section('scripts') }}, {{ include('partial') }}).illuminate/view.@foreach, @component)?View facade or creating a custom PlatesServiceProvider.Route::get('/dashboard', function () {
return app('plates.engine')->render('dashboard', ['user' => auth()->user()]);
});
Mailable class for email templates.
// app/Mail/WelcomeMail.php
public function build()
{
return $this->markdown('emails.welcome', [], function ($message) {
$message->withPlatesData(['user' => $this->user]);
});
}
mix.js('resources/js/app.js', ['version' => config('app.version')])).// app/Providers/RouteServiceProvider.php
Route::macro('plates', function ($path, $data = []) {
return app('plates.engine')->render($path, $data);
});
View facade entirely:
// app/Providers/AppServiceProvider.php
View::macro('make', function ($path, $data = [], $mergeData = []) {
return app('plates.engine')->render($path, $data);
});
config/view.php to point to Plates’ engine:
'engine' => function () {
return new League\Plates\Engine(resource_path('views'));
},
@foreach, @component) as Plates extensions:
// app/Extensions/BladeCompat.php
use League\Plates\Extension\ExtensionInterface;
class BladeCompat implements ExtensionInterface
{
public function register(Engine $engine)
{
$engine->registerFunction('foreach', function ($items, $keyVar, $valueVar) {
// Implement Blade-like foreach logic
});
}
}
| Blade Syntax | Plates Equivalent |
|---|---|
@extends('layout') |
{{ layout('layout') }} |
@section('title') |
{{ section('title') }}...{{ stop() }} |
@include('partial') |
{{ include('partial') }} |
@foreach |
Custom extension (see above) |
| `{{ $var | e }}` |
data() method to pass __() translations.asset() extension.master.blade.php) to Plates layouts.@component) with Plates extensions last.Cache::remember() or Plates extensions).How can I help you explore Laravel packages today?