Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/BlazeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\View;
use Illuminate\View\Engines\CompilerEngine;

class BlazeServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -48,11 +49,20 @@ public function boot(): void
}

/**
* Share the BlazeRuntime instance with all views.
* Make the BlazeRuntime instance available to Blade views.
*/
protected function registerBlazeRuntime(): void
{
View::share('__blaze', $this->app->make(BlazeRuntime::class));
View::composer('*', function (\Illuminate\View\View $view) {
if (Blaze::isDisabled()) {
return;
}

// Avoid injecting the BlazeRuntime into non-Blade views (like Statamic's Antlers)
if ($view->getEngine() instanceof CompilerEngine) {
$view->with('__blaze', $this->app->make(BlazeRuntime::class));
}
});
}

/**
Expand Down