- How do I install jenssegers/blade in a plain PHP project?
- Install it with Composer using composer require jenssegers/blade. The package pulls in illuminate/view and its Illuminate dependencies automatically, so no full Laravel installation is needed. You then create a Blade instance with your view path and compiled cache path, and call render() to output a .blade.php template. Any PSR-4 project can use it, including legacy apps, CLI tools, and batch jobs.
- Which Laravel versions does jenssegers/blade support?
- The package is a thin wrapper around illuminate/view, so its real compatibility ceiling is the Illuminate version it allows. The last release, v2.0.1 from 2024-03-18, was essentially support for Laravel 11. Because it is a single-maintainer package with a reactive release model, check the Composer constraints before adopting it and pin your Illuminate versions deliberately. Treat Illuminate upgrades as rehearsed changes rather than incidental ones.
- Can I use @extends, @section, @include and @each outside of Laravel?
- Yes. jenssegers/blade uses the actual Blade compiler, so inheritance, sections, includes, loops, conditionals, components, and custom directives all work the same way they do inside Laravel. It is not a reimplementation or a subset. That is the main reason to choose it over plain PHP includes: you keep layouts, partials, and one escaping model across your codebase.
- Why does my template throw an error when it calls route(), asset() or @csrf?
- Those come from Laravel's framework layer, not from Blade itself. Helpers such as route(), url(), asset(), config(), csrf_field(), old(), env() and the translation function are absent, and directives like @csrf, @vite, @livewire and @inertia are not registered. Directives such as @auth, @guest, @can, @env, @lang and @error will compile but fail at render time because the services they resolve were never bound. The failures appear only when that branch executes, so your tests must cover every branch, not just the happy path.
- How do I add a custom Blade directive with jenssegers/blade?
- Call the directive() method on your Blade instance and pass a name plus a closure that returns the compiled PHP string. The wrapper also exposes share() for global variables, composer() for view composers, addNamespace() for namespaced view folders, exists() to check a view, and make() for lower-level access. The public surface is intentionally small, which makes it quick to audit and easy to wrap in your own rendering service if you later need to swap it out.
- Is jenssegers/blade safe against XSS?
- Escaped output works correctly: {{ $value }} compiles to e($value), and that helper ships with illuminate/support, so auto-escaping behaves as it does in Laravel. Your XSS surface is therefore the raw output blocks written with {!! !!}, plus any data you pass into them. Those are greppable, so add a CI check that flags raw output and require review for each occurrence. Blade is not a hostile-input sandbox, so if you need to render untrusted templates, use Twig's sandbox mode instead.
- Does jenssegers/blade work with Slim, Symfony or a legacy PHP app?
- It works with any PHP project that can load Composer dependencies, including Slim, custom frameworks, legacy applications, admin panels and command-line tooling. It is deliberately not a framework: it gives you the rendering layer only, with no router, kernel, service provider or DI container. You remain responsible for wiring configuration and shared data into the Blade instance yourself.
- How does view caching work and where are compiled templates stored?
- The constructor takes your view paths and a compile cache path, and Blade writes compiled PHP files into that cache directory, which must be writable by the process. Clear that directory on deploy whenever templates change. The wrapper does not own a cache invalidation or warming strategy, so for high-throughput or latency-critical rendering you need to plan cache location, permissions and clearing yourself. Also consider a shared cache path if multiple workers render the same views.
- Is jenssegers/blade still maintained and what are the alternatives?
- It has around 858 stars and its most recent release was v2.0.1 on 2024-03-18, which added Laravel 11 support, so maintenance is reactive and single-maintainer. The practical risk is upstream Illuminate drift rather than the wrapper code itself; mitigate it by pinning versions, naming an owner, and scheduling compatibility checks. Alternatives include using illuminate/view directly, Twig for sandboxed or non-Blade needs, plain PHP includes for trivial cases, or adopting full Laravel if you need its helpers and directives.
- Can the same .blade.php files be shared between this package and a real Laravel app?
- Yes, but only if the templates stay free of framework helpers and custom directives. The portability promise is a code-review policy, not something the package enforces, so keep templates to standard Blade syntax if you want to move them into Laravel later untouched. That discipline is also what lets one template language and one partial library span both your Laravel and non-Laravel services.