PHPackages                             impactwave/razorblade - 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. impactwave/razorblade

ActiveLibrary

impactwave/razorblade
=====================

An extension to Laravel's Blade templating engine

11831PHP

Since May 4Pushed 10y ago4 watchersCompare

[ Source](https://github.com/Impactwave/razorblade)[ Packagist](https://packagist.org/packages/impactwave/razorblade)[ RSS](/packages/impactwave-razorblade/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Razorblade
==========

[](#razorblade)

An extension to Laravel's Blade templating engine.

Instalation
-----------

[](#instalation)

#### Requirements

[](#requirements)

- PHP version &gt;= 5.4

#### How to install

[](#how-to-install)

##### Install via Composer:

[](#install-via-composer)

```
composer require impactwave/razorblade

```

##### Register the service provider

[](#register-the-service-provider)

Open the `config/app.php` file included with Laravel, you will see a providers array.

Add the following string to that array:

```
'Impactwave\Razorblade\RazorbladeServiceProvider'
```

Blade Extensions
----------------

[](#blade-extensions)

Besides providing some **new Blade directives** (see below), *Razorblade* also adds **Custom Directives** to Blade.

##### What are Custom Directives?

[](#what-are-custom-directives)

Creating a Blade syntax extension is not too difficult, but it's not very easy either. You'll have to deal with regular expressions and low-level implementation details. In practice, few people have the skills and patience to do it, so extensions are seldom used.

What if you could easily create your own syntactic extensions to Blade and make your templates more readable and easier to write?

*Razorblade* provides you with a simple and easy way to do it, called **Custom Directives**.

You just create a simple static method on a class of your choosing, with a specific call signature, and you can immediately call it from Blade.
Implementing the method itself to perform some useful work is also quite simple.

> Razorblade provides you with some predefined custom directives on the `Impactwave\Razorblade\Directives` class. See the documentation for them further below.

### Simple Custom Directives

[](#simple-custom-directives)

The simplest kind of custom directive allows you to invoke a method and replace the custom directive call with the output from it.
The method can, optionally, receive one or more arguments from the template.

##### Syntax

[](#syntax)

```
@@[class::]method [(args)]

```

> **Note:** `[]` brackets are not part of the syntax, they denote optional elements.

##### Generated pseudo-code

[](#generated-pseudo-code)

```
{{ class::method (args) }}

```

- Parenthesis are optional; ex: `@@a::b` instead of `@@a::b()`.
- `class` is a fully qualified class name; ex: `my\namespace\myClass` or just `myClass`.
- If `class` is not specified, `Impactwave\Razorblade\Directives` is assumed.

##### Custom Directive implementation

[](#custom-directive-implementation)

The method implementing the custom directive should have the following signature:

```
static public function directiveName ($arg1, ...) {}
```

- `$arg1, ...` denotes a list of optional arguments. It may be completely ommited.
- The method should return a string. Alternatively, the output it generates may instead be sent to the normal PHP output buffer, either using `echo` or a markup block (`?> ...markup...  ...markup... ` tags.

It is required if you want to embed PHP code on Blade templates that use Razorblade block custom directives.

> **Warning:** if you use `` tags on Blade templates, block custom directives **will not be compiled**, as inlined PHP blocks split template compilation into separate fragments, which will interfere with the compilation logic.

##### Syntax

[](#syntax-10)

```
@@php:
  $v = "my PHP code";
  // etc...
@@endphp

```

The `Form` utility class
------------------------

[](#the-form-utility-class)

The `Impactwave\Razorblade\Form` class provides several static utility methods that are best used in conjunction with the predefined Razorblade custom directives.

### Form::flash

[](#formflash)

Allows sending flash messages to be viewed on the next request. It has support for 4 types of messages and allows setting an optional title.

> **Hint:** use the `@@flashMessage` or `@@toastrMessage` custom directives for displaying the message.

##### Syntax

[](#syntax-11)

```
flash ($message, $title = '', $type = Form::ALERT_INFO)
```

- `string $message`: The message to be displayed.
- `string $title`: An optional title for the alert box.
- `string $type`: The alert type: `error|info|success|warning`. You can also use one of the `Form::ALERT_xxx` constants.

### Form::fieldIs

[](#formfieldis)

Checks if the field's currently submitted value matches the given value.

If the field's value is an array (being the field name suffixed by `[]`), this will match the reference value against all array values (for instance, in the case of multiple radio buttons for the same field, or for a multi-select dropdown).

##### Syntax

[](#syntax-12)

```
Form::fieldIs ($field, $value)
```

- `string $field`: Field name.
- `string $value`: Field value to match.

### Form::fieldWas

[](#formfieldwas)

Checks if the field's previously submitted value matches the given value.

If the field's value was an array (being the field name suffixed by `[]`), this will match the reference value against all array values (for instance, in the case of multiple radio buttons for the same field, or for a multi-select dropdown).

##### Syntax

[](#syntax-13)

```
Form::fieldWas ($field, $value)
```

- `string $field`: Field name.
- `string $value`: Field value to match.

### Form::setModel

[](#formsetmodel)

Sets the data to be initially displayed on a form, before the form is submitted for the first time.

Use this in conjunction with the `@@field` custom directives and `Form::validate()`.

##### Syntax

[](#syntax-14)

```
Form::setModel ($model)
```

- `array $model`: The form data, as a map of field names to field values.

### Form::validate

[](#formvalidate)

Shortcut method for form data validation.

If validates the form input and, if it fails:

- flashes an error message;
- generates a redirection to the same URL;
- saves on the session the validation error messages and the submitted form values, so that they can be redisplayed on the next request.

> **Hint:** use this in conjunction with `@@field` custom directives to easily create a form with validation.

##### Usage

[](#usage)

Place the `validate` call on the controller method that handles the POST request.

```
$err = Util::validate([
  'password'  => 'required|min:8',
  'password2' => 'required|same:password',
  etc...
]);
if ($err) return $err;
// continue handling the form
```

- `array $rules`: A map of field names to validation rules.
- `array $messages`: \[optional\] Custom error messages. See the Laravel documentation for the `Validator` class.
- `array $customAttributes`: \[optional\] Custom attributes. See the Laravel documentation for the `Validator` class.
- Returns: `false|\Illuminate\Http\RedirectResponse` - `false` if the form validates successfully, otherwise, a redirection response.

##### Requirements

[](#requirements-2)

You must define the following localization keys:

KeyMeaning`app.formValidationFailed`A generic message explaining that the form could not be submitted. Details can be found next to each invalid field.---

License
-------

[](#license)

The MIT license. See the accompanying `LICENSE` file.

---

Copyright © 2016 [Cláudio Silva](https://github.com/claudio-silva) and [Impactwave, Lda](https://github.com/impactwave)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/750f00fdbb8cb2fd1c11c5c26b512217451bb001ac48a77542efa7123b9e2124?d=identicon)[impactwave](/maintainers/impactwave)

---

Top Contributors

[![claudio-silva](https://avatars.githubusercontent.com/u/1999803?v=4)](https://github.com/claudio-silva "claudio-silva (22 commits)")

### Embed Badge

![Health badge](/badges/impactwave-razorblade/health.svg)

```
[![Health](https://phpackages.com/badges/impactwave-razorblade/health.svg)](https://phpackages.com/packages/impactwave-razorblade)
```

PHPackages © 2026

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