PHPackages                             rapidez/blade-directives - 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. rapidez/blade-directives

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

rapidez/blade-directives
========================

Expanded blade directives

1.2.0(2mo ago)3114.5k↓59.8%33GPL-3.0-or-laterPHPPHP ^8.2

Since Jun 28Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/rapidez/blade-directives)[ Packagist](https://packagist.org/packages/rapidez/blade-directives)[ Docs](https://rapidez.io)[ RSS](/packages/rapidez-blade-directives/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (2)Versions (20)Used By (3)

Rapidez Blade Directives
========================

[](#rapidez-blade-directives)

This package adds blade directives that we found we needed in Laravel during development of Rapidez. Like `@slots`, which lets you define optional slots so your `attributes->merge()` always works. Or `@includeFirstSafe` which works the same as `@includeFirst` but will not throw errors if no template was found. All directives included within this package:

- [`@attributes`](#attributes)
- [`@includeFirstSafe`](#includefirstsafe)
- [`@markdown`](#markdown)
- [`@return`](#return)
- [`@slots`](#slots)
- [`@slotdefault` + `@endslotdefault`](#slotdefault)
- [`@includeCached`](#includecached)

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

[](#installation)

```
composer require rapidez/blade-directives

```

Directives
----------

[](#directives)

### @attributes

[](#attributes)

The `@attributes` blade directive allows you to pass the attributes for a html element using an array. It's functionally the same as the `$attributes` of a blade component but you can use it outside of blade components!

#### Usage

[](#usage)

[Example](https://github.com/rapidez/statamic/blob/066b5d336e44890c5b4049f5df3c62b15ed302b2/resources/views/page_builder/form.blade.php#L9)

```
 'text', 'id' => 'test', 'name' => 'some_name'])/>
```

which will result in

```

```

### @includeFirstSafe

[](#includefirstsafe)

The `@includeFirstSafe` blade directive works the same way that `@includeFirst` does however it will not throw an error if all templates do not exsist. Outside of production mode it will alert about the missing templates however.

#### Usage

[](#usage-1)

[Example](https://github.com/rapidez/statamic/blob/066b5d336e44890c5b4049f5df3c62b15ed302b2/resources/views/page_builder.blade.php#L2)

```
@includeFirstSafe(['custom.admin', 'admin'], ['status' => 'complete'])
```

### @markdown

[](#markdown)

You can use the `@markdown` directive to transform markdown into html. Basically, `{!! Str::markdown($text) !!}` but in directive form.

#### Usage

[](#usage-2)

```
@markdown($text)
```

### @return

[](#return)

The `@return` blade directive simply stops any further processing of the current template

#### Usage

[](#usage-3)

[Example](https://github.com/rapidez/statamic/blob/066b5d336e44890c5b4049f5df3c62b15ed302b2/resources/views/page_builder/form.blade.php#L5)

```
@return
```

Or only when a condition is true:

```
@return($someConditionIsTrue)
```

### @slotdefault

[](#slotdefault)

When you've an optional slot this directive gives you a cleaner way of defining a fallback. Normally you do something like this:

```
@if ($slot->isEmpty())
    This is default content if the slot is empty.
@else
    {{ $slot }}
@endif
```

#### Usage

[](#usage-4)

```
@slotdefault('slot')
    This is default content if the slot is empty.
@endslotdefault
```

### @slots

[](#slots)

The `@slots` blade directive is used within blade components. It is used to define optional named slots which will be created if they are not passed. Very useful if named slots might not always be passed but you want to use the `attributes` of this named slot

#### Usage

[](#usage-5)

Within your blade component:

```
@slots(['optionalSlot', 'anotherSlot' => ['contents' => 'dummy text', 'attributes' => ['class' => 'bg-red-500']]])

    {{ $slot }}
    attributes }}>{{ $optionalSlot }}
    attributes->class('text-black') }}>{{ $anotherSlot }}

```

If you enter nothing and only load in the component without passing any named slots it will be

```

    dummy text

```

but if you were to pass the named slots it would look like this:

```

    Regular slot text
    Optional content
    Optional content

```

```

    Regular slot text
    Optional content
    Optional content

```

As you can see it has overwritten the class of the optional slot, but not the `attributes->class()`

If you only wish to change the text without changing attributes you can also pass them as attributes.

```

    Regular slot text

```

```

    Regular slot text
    Optional content
    Optional content

```

### @includeCached

[](#includecached)

Just like [`@include`](https://laravel.com/docs/11.x/blade#including-subviews) but cached. Everything returned will be cached with [`Cache::flexible()`](https://laravel.com/docs/11.x/cache#swr) for 5 minutes; and refreshed in the background until it expires after 24 hours. After that it will be refreshed as usual. The cache key is a combination of the view name and the current slugified url. That way this can be used with multisite setups:

```
include-cache::site-{ Str::slug(url('/')) }-{ $viewName }'

```

#### Usage

[](#usage-6)

```
@includeCached('view.name')
```

#### Notes

[](#notes)

Keep in mind that any dynamic things within the view will not be executed when cached. For example `@push`, see [Blade Stacks](https://laravel.com/docs/11.x/blade#stacks). Also [Blade Icons Deferring](https://github.com/blade-ui-kit/blade-icons#deferring-icons) doesn't work, you have to use these things outside the cached include!

Helpers
-------

[](#helpers)

### optionalDeep

[](#optionaldeep)

Have you heard of [optional()](https://laravel.com/docs/10.x/helpers#method-optional)? This is the supercharged version working at any depth! It makes sure that any missing key will not break your code, especially helpful when mixing Statamic with Blade

#### Usage

[](#usage-7)

It will automatically return the value when casting to string so you can immediately echo out it's value, if you want to get the value use the get method. This will return null if anywhere along the chain the value or key does not exist.

```
{{ optionalDeep($object)->undefinedKey->anotherUndefinedKey }}
{{ optionalDeep($object)->header->usp->link->value() }}
@if(optionalDeep($object)->header->usp->link->value()->isset())
@if(optionalDeep($object)->header->usp->link->value()->get() === 'test')
```

Tip

the [OptionalDeep](https://github.com/rapidez/blade-directives/blob/master/src/OptionalDeep.php#L15) class implements Macroable, allowing you to extend it with your own functions!

License
-------

[](#license)

GNU General Public License v3. Please see [License File](LICENSE) for more information.

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance88

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 53.5% 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 ~60 days

Recently: every ~127 days

Total

18

Last Release

75d ago

Major Versions

0.8.0 → 1.0.02024-11-27

PHP version history (3 changes)0.0.1PHP ^8.0|^8.1|^8.2

1.1.0PHP ^8.0|^8.1|^8.2|^8.3|^8.4

1.2.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/72222911?v=4)[Rapidez](/maintainers/rapidez)[@rapidez](https://github.com/rapidez)

---

Top Contributors

[![royduin](https://avatars.githubusercontent.com/u/1703233?v=4)](https://github.com/royduin "royduin (23 commits)")[![indykoning](https://avatars.githubusercontent.com/u/15870933?v=4)](https://github.com/indykoning "indykoning (11 commits)")[![Jade-GG](https://avatars.githubusercontent.com/u/32514269?v=4)](https://github.com/Jade-GG "Jade-GG (6 commits)")[![Roene-JustBetter](https://avatars.githubusercontent.com/u/85165259?v=4)](https://github.com/Roene-JustBetter "Roene-JustBetter (2 commits)")[![JimmyHoenderdaal](https://avatars.githubusercontent.com/u/101801301?v=4)](https://github.com/JimmyHoenderdaal "JimmyHoenderdaal (1 commits)")

---

Tags

rapidez

### Embed Badge

![Health badge](/badges/rapidez-blade-directives/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[illuminate/view

The Illuminate View package.

13047.0M2.2k](/packages/illuminate-view)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

725173.0k14](/packages/tallstackui-tallstackui)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[hasinhayder/tyro-dashboard

Tyro Dashboard - Beautiful admin dashboard for managing Tyro roles, privileges, users, and settings

5443.8k](/packages/hasinhayder-tyro-dashboard)

PHPackages © 2026

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