Blade Capture Directive
Blade Capture Directive stats
- Downloads
- 1.6M
- Stars
- 40
- Open Issues
- 2
- Forks
- 2
Create inline partials in your Blade templates with ease.
Blade Capture Directive for Laravel
The blade-capture-directive package by Ryan Chandler enhances Blade, Laravel's templating engine, by introducing a powerful @capture directive. This directive simplifies the creation of inline partials within Blade templates, allowing developers to encapsulate and reuse code snippets without creating separate partial files.
Key Features:
- Inline Partials Creation: Easily capture and reuse segments of Blade templates.
- Dynamic Content: Supports arguments within captured blocks, enabling dynamic output.
- Scope Inheritance: Captured blocks inherit data from the parent scope, simplifying data handling.
Installation:
Install the package via Composer:
composer require ryangjchandler/blade-capture-directive
Usage:
Define a captured block with @capture and end it with @endcapture. Assign the block to a PHP variable which becomes a callable Closure.
@capture($greeting) Hello, world!@endcapture {{ $greeting() }}
Advanced Usage:
Pass arguments to modify the output dynamically:
@capture($personalizedGreeting, $name) Hello, {{ $name }}!@endcapture {{ $personalizedGreeting('Ryan') }}
Handle multiple arguments and default values:
@capture($customGreeting, $name, $prefix = 'Hello, ') {{ $prefix }}{{ $name }}!@endcapture {{ $customGreeting('Ryan') }}{{ $customGreeting('Taylor', 'Hey, ') }}
Testing:
Run tests using:
composer test
Contributing and Support:
Contributions are welcome, and the project's changelog, security policy, and contribution guidelines can be found in the repository.
Licensing:
Distributed under the MIT License. Full license details are available in the repository.
This package is ideal for developers looking to streamline their Blade views by reducing redundancy and promoting reusability within their Laravel applications.