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.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


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
LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search