Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Blade Capture Directive

ryangjchandler/blade-capture-directive image

Blade Capture Directive stats

Downloads
1.6M
Stars
40
Open Issues
2
Forks
2

View on GitHub →

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.


Ryangjchandler Blade Capture Directive Related Articles

Hooks for Alpine.js image

Hooks for Alpine.js

Read article
Enforce the Disposal of Objects in PHP image

Enforce the Disposal of Objects in PHP

Read article
A Flat-File Database Driver for Eloquent image

A Flat-File Database Driver for Eloquent

Read article
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift