PHPackages                             jobinja/blade-macro - 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. jobinja/blade-macro

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

jobinja/blade-macro
===================

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

2.0.0(7y ago)74.9k4[1 issues](https://github.com/Jobinja/blade-macro/issues)MITPHPPHP ^7.1

Since Dec 24Pushed 7y ago4 watchersCompare

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

READMEChangelogDependencies (7)Versions (12)Used By (0)

Blade Macro
-----------

[](#blade-macro)

This package introduces a new *blade directive* called `@macro` which allows reusable scope-protected *blade* code blocks. Just like what `@include` does but with zero runtime I/O.

`@include` uses native PHP `include` directive, which causes runtime I/O, **Event if Opcache is fully enabled**. But sometimes `@include` is used when we want to just **Don't repeat ourselves**But this abstraction should not cause any performance bottleneck.

### Installation

[](#installation)

For Laravel &gt;= 5.5.0:

```
composer require jobinja/blade-macro
```

For Laravel &lt;= 5.3.0:

```
composer require jobinja/blade-macro:1.0.*
```

### Usage

[](#usage)

Just use the following service provider in your `app.php`:

```
[
    \JobinjaTeam\BladeMacro\JobinjaBladeMacroServiceProvider::class,
    //...
]
```

Then you can simply replace your needed old `@include` directives with the new `@macro` one:

```
@include('some_partial', ['some_var' => 'some_value')

// Should be replaced with:
@macro('some_partial', ['some_var' => 'some_value'])
```

### Configuration

[](#configuration)

By default the package re-compiles blade views on each request in **development** environment, if you want to disable this feature run:

```
php artisan vendor:publish --provider=JobinjaTeam\BladeMacro\JobinjaBladeMacroServiceProvider
```

and config the package based on your needs.

### Problem

[](#problem)

Please see [\#16583](https://github.com/laravel/framework/pull/16583) or simply read the following:

Consider the following loop:

```
@for($i=1; $i < 500000; $i++)
    @include('iteration_presenter', ['iteration' => $i])
@endfor
```

The above code will be replaced by something like the following:

```

```

The above code **includes** the **iteration\_presenter.blade.php** file for 5,000,000 times, which causes heavy I/O calls, but the only reason we have used the `iteration_presenter` partial is to create more abstraction and don't repeat ourselves.

### Solution

[](#solution)

Instead of using native `include` directive we have created a new `@macro` directive which simply copy/pastes the partial content in compile time, and simply there is no I/O then:

```
@for($i=1; $i < 500000; $i++)
    @macro('iteration_presenter', ['iteration' => $i])
@endfor
```

The above `@macro` directive will be translated to the following:

```

```

### Running tests

[](#running-tests)

```
composer test
```

### License

[](#license)

Licensed under MIT, part of the effort for making [Jobinja.ir](https://jobinja.ir) better.

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

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 ~53 days

Recently: every ~132 days

Total

11

Last Release

2892d ago

Major Versions

1.0.9 → 2.0.02018-06-08

PHP version history (2 changes)1.0.0PHP ^5.5.9 || ^7.0

2.0.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ce48e840de2a338377b9c076bb90fc36407b3264bc91bda3ecb9248d57b193f?d=identicon)[jobinja](/maintainers/jobinja)

---

Tags

laravelperformancebladetemplatingblade-optimize

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jobinja-blade-macro/health.svg)

```
[![Health](https://phpackages.com/badges/jobinja-blade-macro/health.svg)](https://phpackages.com/packages/jobinja-blade-macro)
```

###  Alternatives

[blade-ui-kit/blade-icons

A package to easily make use of icons in your Laravel Blade views.

2.5k34.2M309](/packages/blade-ui-kit-blade-icons)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[moonshine/moonshine

Laravel administration panel

1.3k217.1k59](/packages/moonshine-moonshine)[spatie/laravel-blade-comments

Add debug comments to your rendered output

177325.5k](/packages/spatie-laravel-blade-comments)[fitztrev/laravel-html-minify

Minifies the HTML output of Laravel 4 applications

414211.4k](/packages/fitztrev-laravel-html-minify)

PHPackages © 2026

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