preflow / blade
Preflow Blade adapter — Laravel Blade template engine implementation
Requires
- php: >=8.4
- illuminate/events: ^11.0 || ^12.0
- illuminate/filesystem: ^11.0 || ^12.0
- illuminate/view: ^11.0 || ^12.0
- preflow/core: ^0.60 || @dev
- preflow/view: ^0.72 || @dev
Requires (Dev)
- phpunit/phpunit: ^11.0
- preflow/testing: ^0.64 || @dev
Suggests
None
Provides
None
Conflicts
- preflow/core: <0.60
- preflow/view: <0.72
Replaces
None
- dev-main
- v0.76.0
- v0.75.0
- v0.74.0
- v0.73.0
- v0.72.1
- v0.72.0
- v0.71.1
- v0.71.0
- v0.70.0
- v0.69.2
- v0.69.1
- v0.69.0
- v0.68.1
- v0.68.0
- v0.67.0
- v0.66.2
- v0.66.1
- v0.66.0
- v0.65.0
- v0.64.0
- v0.63.2
- v0.63.1
- v0.63.0
- v0.62.0
- v0.61.0
- v0.60.1
- v0.60.0
- v0.59.0
- v0.58.1
- v0.58.0
- v0.57.0
- v0.56.1
- v0.56.0
- v0.55.0
- v0.54.1
- v0.54.0
- v0.53.2
- v0.53.1
- v0.53.0
- v0.52.0
- v0.51.0
- v0.50.0
- v0.49.1
- v0.49.0
- v0.48.5
- v0.48.4
- v0.48.3
- v0.48.2
- v0.48.1
- v0.48.0
- v0.47.1
- v0.47.0
- v0.46.1
- v0.46.0
- v0.45.0
- v0.44.0
- v0.43.0
- v0.42.1
- v0.42.0
- v0.41.2
- v0.41.1
- v0.41.0
- v0.40.0
- v0.39.0
- v0.38.0
- v0.37.0
- v0.36.0
- v0.35.0
- v0.34.1
- v0.34.0
- v0.33.0
- v0.32.0
- v0.31.0
- v0.30.0
- v0.29.0
- v0.28.0
- v0.27.1
- v0.27.0
- v0.26.0
- v0.25.1
- v0.25.0
- v0.24.1
- v0.24.0
- v0.23.0
- v0.22.1
- v0.22.0
- v0.21.0
- v0.20.0
- v0.19.2
- v0.19.1
- v0.19.0
- v0.18.1
- v0.18.0
- v0.17.2
- v0.17.1
- v0.17.0
- v0.16.2
- v0.16.1
- v0.16.0
- v0.15.0
- v0.14.2
- v0.14.1
- v0.14.0
- v0.13.1
- v0.13.0
- v0.12.0
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.4
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.1
- v0.9.0
- v0.8.0
- v0.7.0
- v0.6.0
This package is auto-updated.
Last update: 2026-11-14 19:29:54 UTC
README
Laravel Blade adapter for Preflow. Implements TemplateEngineInterface using illuminate/view, with custom directives for asset collection and template functions.
Installation
composer require preflow/blade
Requires PHP 8.4+ and illuminate/view 11+.
What's included
| Component | Description |
|---|---|
BladeEngine |
TemplateEngineInterface implementation wrapping Blade's Factory and BladeCompiler |
@css / @endcss |
Directive pair for co-located CSS via AssetCollector |
| Custom directives | Template functions registered via addFunction() become @name(...) directives |
BladeEngine
use Preflow\Blade\BladeEngine; use Preflow\View\AssetCollector; use Preflow\View\NonceGenerator; $assets = new AssetCollector(new NonceGenerator(), isProd: true); $engine = new BladeEngine( templateDirs: [__DIR__ . '/templates', __DIR__ . '/app/pages'], assetCollector: $assets, debug: false, cachePath: __DIR__ . '/storage/blade-cache', // null = system temp dir ); $html = $engine->render('blog.post', ['post' => $post]); $engine->exists('partials.nav'); // bool $engine->getTemplateExtension(); // 'blade.php'
Templates
Blade templates use .blade.php extension with standard Blade syntax:
{{-- resources/views/blog/post.blade.php --}} <h1>{{ $post->title }}</h1> <div>{!! $post->body !!}</div> @if($post->published) <span>Published {{ $post->date }}</span> @endif @foreach($comments as $comment) <p>{{ $comment->text }}</p> @endforeach
Co-located styles
Use @css / @endcss to register CSS with the AssetCollector:
@css .post-title { font-size: 2rem; font-weight: 700; } .post-body { line-height: 1.7; } @endcss <h1 class="post-title">{{ $post->title }}</h1> <div class="post-body">{!! $post->body !!}</div>
Layout with extends and sections
{{-- _layout.blade.php --}} <!doctype html> <html> <head> <meta charset="utf-8"> <title>@yield('title', 'App')</title> </head> <body> @yield('content') </body> </html>
{{-- page.blade.php --}} @extends('_layout') @section('title', 'Blog') @section('content') <h1>My Blog</h1> @endsection
Custom function directives
Template functions registered via addFunction() become Blade directives. With isSafe: true, output is rendered raw; otherwise it is escaped via e().
$engine->addFunction(new TemplateFunctionDefinition( name: 'component', callable: fn (string $name, array $props = []) => $renderer->render($name, $props), isSafe: true, ));
@component('Counter', ['count' => 0])
Global variables
$engine->addGlobal('siteName', 'My App');
<footer>{{ $siteName }}</footer>
Live parts: @live
The Blade twin of Twig's {% live %} (preflow/core's page cache, live parts):
@live(['number' => $object->number]) <button aria-pressed="{{ in_album($number) ? 'true' : 'false' }}">…</button> @endlive
- The body is taken out of the template before Blade compiles it, into a view file of its own
(
{cache}/live/{hash}.blade.php, written again from the template when the cache is cleared), and rendered with only the given values and the globals. The values are scalars and arrays;@livewithout them works too. - While a page renders for the page cache,
@liveprints a signed placeholder (file, index, values) instead; the body is rendered for each visitor when the page is served. Otherwise it renders in place. - Not nested, and only in template files (not in strings compiled on the fly).
- The placeholder names the template by its view name in the template folders, or, in a component's own template, by the component class, with the body's hash: after a cleared cache the body is taken again from the template only while it still has that hash. A template outside both renders its live blocks in place and keeps the page from being stored.
Freshness and expiry: @freshness, @expires
The same as Twig's {% freshness %} and {% expires %} (preflow/core's page cache):
@freshness('next-visit') @foreach ($others as $job) … @endforeach @endfreshness @freshness('timed', every: '12h') {{ $weather() }} @endfreshness @expires(at: $event->startsAt) @expires(in: '1h')
- Names:
'fresh','next-visit','timed'; onlytimedtakesevery('30m','12h','2d'or seconds). Nested, the innermost wins; a throw inside closes the scope. A timed page never outlives the page cache'smax_age(4 h by default): raise it for longer times (up to 20 h). - As with every Blade directive,
@endfreshnessright after a letter or digit (x@endfreshness) is not seen: put a space or a tag before it.
Engine configuration
Set APP_ENGINE=blade in your .env to use Blade. Preflow's Application will automatically create a BladeEngine and register all extension providers.