ryangjchandler/blade-capture-directive
Adds a @capture Blade directive to capture and store rendered template output in a variable for reuse later in the view. Useful for building snippets, components, and deferred sections without extra buffering or complicated view logic.
@include directives or view composers).@capture), requiring updated Blade tests (e.g., unit tests for template rendering, snapshot tests for UI consistency).@capture blocks, dynamic content). Mitigate with:
@capture vs. @include.@include, view composers)?@include directives with @capture to test ergonomics.@capture blocks).laravel-blade-linter) to enforce usage guidelines.@once, @stack). Test with:
@capture('test') {{ $slot }} @endcapture
@stack('scripts') <!-- Does this still work? -->
@capture content doesn’t break reactivity (e.g., Alpine’s x-data).php artisan view:clear) works post-integration.composer require ryangjchandler/blade-capture-directive.config/view.php.@capture scenarios.@capture blocks >50 lines).@extends) alongside @capture for large layouts.@capture examples in new hire templates.php artisan view:clear --force.view.compiled path if needed).@include as a fallback.// config/view.php
'compiled' => storage_path('framework/views').'/'.env('APP_ENV').'/captured',
@capture for complex logic, risk of tight coupling. Consider:
@capture only for presentational reuse.| Failure Scenario | Impact | Mitigation |
|---|---|---|
Syntax error in @capture block |
White screen or partial rendering | Use try-catch in Blade or rollback. |
Overuse of nested @capture |
Unreadable templates, slow parsing | Enforce linting rules. |
| Dynamic content breaks caching | Increased server load | Use @once for static partials. |
IDE misinterprets @capture |
Poor developer experience | Document IDE workarounds. |
| Package abandonment | Security/feature gaps | Fork or monitor GitHub issues. |
@capture vs. @include trade-offs.@capture usage in PRs (e.g., "Why not @include?").@capture (e.g., for logic-heavy sections).@capture.How can I help you explore Laravel packages today?