PHPackages                             bitpress/blade-extensions - 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. bitpress/blade-extensions

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

bitpress/blade-extensions
=========================

Laravel Blade extension classes

1.0.0(8y ago)13610.2k5[2 issues](https://github.com/bitpressio/blade-extensions/issues)1MITPHP

Since Nov 30Pushed 7y ago4 watchersCompare

[ Source](https://github.com/bitpressio/blade-extensions)[ Packagist](https://packagist.org/packages/bitpress/blade-extensions)[ RSS](/packages/bitpress-blade-extensions/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (1)

Laravel Blade Extension Classes
===============================

[](#laravel-blade-extension-classes)

This Laravel &gt;=5.5 package allows you to organize your Blade extensions into classes. It provides a simple container pass that registers all your extensions with the Blade compiler using a simple tag.

Organizing Blade extensions as classes in the service container allows you to group extension functionality within one object, allowing you to inject dependencies through the service container and provide shared protected/private methods.

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

[](#installation)

You can install this package via Composer using the following command:

```
composer require bitpress/blade-extensions

```

This package will automatically register the included service provider.

Usage
-----

[](#usage)

At a high level, the goal of this package is to make it easy and convenient to register blade extensions as classes from the service container automatically using service container tagging. Here's the gist of how it works:

1. Create a new Extension class with `php artisan make:blade Example`
2. Register the Extension in a service provider's `register()` method
3. Tag the service with `blade.extension`
4. The `BladeExtensionServiceProvider` automatically wires up the directives in the blade compiler during `boot()`.

### Creating a new Extension Class

[](#creating-a-new-extension-class)

It would be annoying to create a new extension class from scratch each time, so this package provides an artisan command to create your extensions under the `App\Blade` namespace:

```
# Creates App\Blade\CartExtension
php artisan make:blade Cart

```

### Defining the Extension Directives and Conditionals

[](#defining-the-extension-directives-and-conditionals)

Once you create a blade extension class, you can define supported directives, conditionals, or both. Custom Blade directives and conditionals are simply [PHP callables](http://php.net/manual/en/language.types.callable.php):

```
