Create inline partials in your Blade templates with ease

Overview

Create inline partials in your Blade templates with ease.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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

You can install the package via Composer:

composer require ryangjchandler/blade-capture-directive

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!

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
Releases(v0.2.2)
  • v0.2.2(Sep 2, 2022)

  • v0.2.1(Aug 23, 2022)

    What's Changed

    • chore(deps): bump dependabot/fetch-metadata from 1.3.0 to 1.3.1 by @dependabot in https://github.com/ryangjchandler/blade-capture-directive/pull/3
    • chore(deps): bump dependabot/fetch-metadata from 1.3.1 to 1.3.3 by @dependabot in https://github.com/ryangjchandler/blade-capture-directive/pull/4
    • fix: maintain $this binding of captured closure by @ryangjchandler in https://github.com/ryangjchandler/blade-capture-directive/pull/5

    New Contributors

    • @dependabot made their first contribution in https://github.com/ryangjchandler/blade-capture-directive/pull/3

    Full Changelog: https://github.com/ryangjchandler/blade-capture-directive/compare/v0.2.0...v0.2.1

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Mar 11, 2022)

    What's Changed

    • feature: capture enclosing environment by @ryangjchandler in https://github.com/ryangjchandler/blade-capture-directive/pull/2

    New Contributors

    • @ryangjchandler made their first contribution in https://github.com/ryangjchandler/blade-capture-directive/pull/2

    Full Changelog: https://github.com/ryangjchandler/blade-capture-directive/compare/v0.1.0...v0.1.1

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Mar 10, 2022)

Owner
Ryan Chandler
Ryan Chandler
Cache chunks of your Blade markup with ease. 🔪

Blade Cache Directive Cache chunks of your Blade markup with ease. Installation You can install the package via Composer: composer require ryangjchand

Ryan Chandler 155 Dec 10, 2022
Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views

Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views. In all essence, it's a collection of useful utilities, connecting the dots between different parts of the TALL stack. It was made for Blade, Laravel's powerful templating engine.

Blade UI Kit 1.2k Jan 5, 2023
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Ollie Codes 19 Jul 5, 2021
Vim syntax highlighting for Blade templates.

vim-blade Vim syntax highlighting for Blade templates (Laravel 4+). This plugin contributes to vim-polyglot language pack. Installation Using vim-plug

Jason Walton 194 Dec 1, 2022
Use Blade templates without the full Laravel framework

blade Use Laravel Blade templates as a standalone component without the full Laravel framework Full documentation is available at http://duncan3dc.git

Craig Duncan 138 Dec 7, 2022
API Blueprint Renderer for Laravel, customizable via Blade templates

API Blueprint Renderer for Laravel This Laravel package Blueprint Docs renders your API Blueprint. It comes with a standard theme that you can customi

Michael Schmidt-Voigt 225 Sep 16, 2022
A library for using Laravel Blade templates in WordPlate.

A library for using Laravel Blade templates in WordPress/WordPlate. Installation Require this package, with Composer, in the root directory of y

null 28 Nov 28, 2022
Adds a widget and REST endpoint for the purpose of displaying post revisions inline on the frontend.

Post History This widget allows visitors to easily diff posts against their earlier revisions, displaying diffs of HTML inline. It should be plug and

Human Made 4 Dec 12, 2022
Use Kafka Producers and Consumers in your laravel app with ease!

Laravel Kafka Do you use Kafka in your laravel packages? All packages I've seen until today, including some built by myself, does not provide a nice s

Mateus Junges 325 Jan 5, 2023
Cast your Eloquent model attributes to Value Objects with ease.

Laravel Value Objects Cast your Eloquent model attributes to value objects with ease! Requirements This package requires PHP >= 5.4. Using the latest

Red Crystal Code 23 Dec 30, 2022
Laravel-model-mapper - Map your model attributes to class properties with ease.

Laravel Model-Property Mapper This package provides functionality to map your model attributes to local class properties with the same names. The pack

Michael Rubel 15 Oct 29, 2022
Create Laravel views (blade template) using 'php artisan' command-line interface

About LaraBit Have you ever wonder to create Laravel views (Blade Templates) using the same type of artisan commands that you usually use to create ne

Ragib MRB 5 Oct 15, 2021
A package to easily make use of Iconic icons in your Laravel Blade views.

Blade Iconic A package to easily make use of Iconic icons in your Laravel Blade views. For a full list of available icons see the SVG directory. Iconi

Malik Alleyne-Jones 17 Aug 25, 2022
A package to easily make use of Simple Icons in your Laravel Blade views.

Blade Simple Icons A package to easily make use of Simple Icons in your Laravel Blade views. For a full list of available icons see the SVG directory.

UB Labs 12 Jan 17, 2022
Cagilo - a set of simple components for use in your views Laravel Blade.

Cagilo - a set of simple components for use in your views Laravel Blade. Official Documentation Documentation for Cagilo can be found on its we

Cagilo 151 Dec 6, 2022
A Laravel Code Generator based on your Models using Blade Template Engine

Laravel Code Generator is a PHP Laravel Package that uses Blade template engine to generate code for you. The difference between other code generators

Victor Yoalli 59 Dec 5, 2022
A package to easily make use of SVG icons in your Laravel Blade views.

Blade Icons A package to easily make use of SVG icons in your Laravel Blade views. Originally "Blade SVG" by Adam Wathan. Turn... <!-- camera.svg -->

Blade UI Kit 1.7k Jan 2, 2023
Custom Blade components to add sortable/drag-and-drop HTML elements in your apps.

Laravel Blade Sortable Demo Repo Installation You can install the package via composer: composer require asantibanez/laravel-blade-sortable After the

Andrés Santibáñez 370 Dec 23, 2022
A package to easily make use of Iconsax in your Laravel Blade views.

Blade Iconsax A package to easily make use of Iconsax in your Laravel Blade views. This package contains 1.000 icons in 6 diferent styles, a total of

Guilherme Saade 4 Oct 22, 2022