Polyscope - The agent-first dev environment for Laravel

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

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Lucky Media logo

Lucky Media

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

Lucky Media
PhpStorm logo

PhpStorm

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

PhpStorm
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
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
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