PHPackages                             alamin-appnap/blade-capture-directive - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. alamin-appnap/blade-capture-directive

ActiveLibrary[Templating &amp; Views](/categories/templating)

alamin-appnap/blade-capture-directive
=====================================

Create inline partials in your Blade templates with ease.

v2.0.5(2y ago)05MITPHPPHP ^8.1

Since Mar 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/alaminAppnap/filament-profile-package)[ Packagist](https://packagist.org/packages/alamin-appnap/blade-capture-directive)[ Docs](https://github.com/alaminAppnap/filament-profile-package)[ RSS](/packages/alamin-appnap-blade-capture-directive/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (12)Versions (4)Used By (0)

Create inline partials in your Blade templates with ease.
=========================================================

[](#create-inline-partials-in-your-blade-templates-with-ease)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4fa590b5904944393c4a9db22ccfd9cc374986e61379cb039703546a8c87f789/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7279616e676a6368616e646c65722f626c6164652d636170747572652d6469726563746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryangjchandler/blade-capture-directive)[![GitHub Tests Action Status](https://camo.githubusercontent.com/8cbc388f9cafda90b9015eec28ebc953728836e5b3d2429df48454a368ad7b2f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7279616e676a6368616e646c65722f626c6164652d636170747572652d6469726563746976652f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/ryangjchandler/blade-capture-directive/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/cdcf7a2667e0143136fc92ee16ddb90bb3b4ee0271c04a7e252ed53fb0bd4786/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7279616e676a6368616e646c65722f626c6164652d636170747572652d6469726563746976652f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/ryangjchandler/blade-capture-directive/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/a4d24795faf2c119730eff3192baa6343e0dfb85f2f950f384726e521c927b10/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7279616e676a6368616e646c65722f626c6164652d636170747572652d6469726563746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryangjchandler/blade-capture-directive)

This package introduces a new `@capture` directive that allows you to capture small parts of your Blade templates and re-use them later on without needing to extract them into partials.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require ryangjchandler/blade-capture-directive
```

Usage
-----

[](#usage)

This package adds a new pair of directives: `@capture` and `@endcapture`.

The `@capture` directive will capture all of your Blade until it reaches an `@endcapture` directive. It takes the code and stores it inside of a variable for usage later on.

```
@capture($hello)
    Hello, world!
@endcapture
```

The directive requires at least 1 argument. This argument should be a PHP variable that you would like to assign your partial to. The variable itself will become a `Closure` that can be invoked inside of Blade echo tags (`{{  }}`) anywhere after it's definition.

```
@capture($hello)
    Hello, world!
@endcapture

{{ $hello() }}
```

The above code will invoke your captured Blade code and output `Hello, world!` when compiled by Laravel and rendered in the browser.

The `@capture` directive also supports arguments. This means you can capture generalised chunks of Blade and change the output dynamically. This is achieved by specifying a comma-separated list of PHP variables like so:

```
@capture($hello, $name)
    Hello, {{ $name }}!
@endcapture
```

The above code will require that a name is passed to `$hello()`, like below:

```
@capture($hello, $name)
    Hello, {{ $name }}!
@endcapture

{{ $hello('Ryan') }}
```

The Blade will compile this and your view will output `Hello, Ryan!`. Cool, right?

The list of arguments can be treated like any set of arguments defined on a function. This means you can assign default values and specify multiple arguments:

```
@capture($hello, $name, $greeting = 'Hello, ')
    {{ $greeting }} {{ $name }}!
@endcapture

{{ $hello('Ryan') }}
{{ $hello('Taylor', 'Yo, ') }}
```

The above code will now output `Hello, Ryan!` as well as `Yo, Taylor!`. This is really cool, I know!

### Inheriting scope

[](#inheriting-scope)

All captured blocks will inherit the parent scope, just like a regular partial would in Blade. This means you can use any data passed to the view without having to pass it through to the block manually.

```
@php($name = 'Ryan')

@capture($hello)
    Hello, {{ $name }}!
@endcapture

{{ $hello() }}
```

> If your captured block has a parameter with the same name as a predefined variable from the inherited scope, the block's parameter will always take precedence.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Ryan Chandler](https://github.com/ryangjchandler)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

835d ago

Major Versions

v1.0.2 → v2.0.52024-03-22

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/101187208?v=4)[MD.AL-AMIN](/maintainers/alaminAppnap)[@alaminAppnap](https://github.com/alaminAppnap)

---

Top Contributors

[![alaminAppnap](https://avatars.githubusercontent.com/u/101187208?v=4)](https://github.com/alaminAppnap "alaminAppnap (4 commits)")

---

Tags

laravelalaminAppnapfilament-profile-package

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/alamin-appnap-blade-capture-directive/health.svg)

```
[![Health](https://phpackages.com/badges/alamin-appnap-blade-capture-directive/health.svg)](https://phpackages.com/packages/alamin-appnap-blade-capture-directive)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M101](/packages/dedoc-scramble)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.9k3](/packages/defstudio-telegraph)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
