PHPackages                             helsingborg-stad/blade - 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. helsingborg-stad/blade

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

helsingborg-stad/blade
======================

Use Laravel Blade in any PHP project.

3.5.1(1y ago)554.8k↑23.5%4MITPHPPHP ^7.4|^8.0CI passing

Since Mar 14Pushed 1y ago4 watchersCompare

[ Source](https://github.com/helsingborg-stad/Blade)[ Packagist](https://packagist.org/packages/helsingborg-stad/blade)[ Docs](https://github.com/helsingborg-stad/blade)[ RSS](/packages/helsingborg-stad-blade/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (18)Used By (4)

[![Contributors](https://camo.githubusercontent.com/2d97b23a8e4d39fa5d4f7dd614fda585be7a83ce04d99efb09d2813f8ef3c5cc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f68656c73696e67626f72672d737461642f426c6164652e7376673f7374796c653d666c61742d737175617265)](https://github.com/helsingborg-stad/Blade/graphs/contributors)[![Forks](https://camo.githubusercontent.com/3f57f70a312003f38b8ee7bcc5bc4563bf11a42140b84846345d6a1d6e31fd90/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f68656c73696e67626f72672d737461642f426c6164652e7376673f7374796c653d666c61742d737175617265)](https://github.com/helsingborg-stad/Blade/network/members)[![Stargazers](https://camo.githubusercontent.com/a1032748d7d02757a97934c2ad8c30477ad42da088827dc81fb23f7b55194201/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f68656c73696e67626f72672d737461642f426c6164652e7376673f7374796c653d666c61742d737175617265)](https://github.com/helsingborg-stad/Blade/stargazers)[![Issues](https://camo.githubusercontent.com/774b0d1baeb6316a5e4a364b497be93be79e86d46b5e681fdce7e99c0090c371/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f68656c73696e67626f72672d737461642f426c6164652e7376673f7374796c653d666c61742d737175617265)](https://github.com/helsingborg-stad/Blade/issues)[![License](https://camo.githubusercontent.com/71e60d0e4bb7d409cf1634605f53d53d95231041e120022460feeb60a90b591b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f68656c73696e67626f72672d737461642f426c6164652e7376673f7374796c653d666c61742d737175617265)](https://raw.githubusercontent.com/helsingborg-stad/Blade/main/LICENSE)[![PHP 8.2](https://github.com/helsingborg-stad/Blade/actions/workflows/php-test.yaml/badge.svg)](https://github.com/helsingborg-stad/Blade/actions/workflows/php-test.yaml/badge.svg)

[ ![Logo](docs/images/hbg-github-logo-combo.png)](https://github.com/helsingborg-stad/Blade)Blade
=====

[](#blade)

Use [Laravel Blade](https://laravel.com/docs/blade) in any PHP project.
**If you don't know about Blade yet, please refer to the [official documentation](https://laravel.com/docs/blade).**

[Report Bug](https://github.com/helsingborg-stad/Blade/issues) · [Request Feature](https://github.com/helsingborg-stad/Blade/issues)

Requirements
------------

[](#requirements)

- PHP ^7.4 | ^8.0
- Composer

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

[](#installation)

```
composer require helsingborg-stad/Blade
```

Usage
-----

[](#usage)

### Configuration

[](#configuration)

#### Cache path

[](#cache-path)

- The cache path can be set by passing the path to the constructor of the BladeService.
- If no cache path is set, the Blade Service will use the system's temporary directory.
- The cache path can be overriden by defining the `BLADE_CACHE_PATH` environment constant.

### Initialize blade engine:

[](#initialize-blade-engine)

This can be done either as a local instance or as a global reusable instance. The global instance is recommended better performance and less memory usage.

#### Locally

[](#locally)

```
$viewPaths    = ['path/to/view/files'];
$cachePath    = 'path/to/cache/files';
$bladeService = new BladeService($viewPaths, $cachePath);
```

#### Globally (for convenient reuse)

[](#globally-for-convenient-reuse)

```
$viewPaths    = ['path/to/view/files'];
$cachePath    = 'path/to/cache/files';
$bladeService = GlobalBladeService::getInstance($viewPaths, $cachePath);

// You can now reuse the same instance by calling:
$sameInstance = GlobalBladeService::getInstance($viewPaths, $cachePath);
```

Note

If calling `GlobalBladeService::getInstance` with parameters after the first call, the $viewPaths will be added and the $cachePath parameter will be ignored.

### Render view

[](#render-view)

```
$viewFile = 'foo.blade.php';
$html     = $bladeService->makeView($viewFile)->render();
```

#### Render view with variables

[](#render-view-with-variables)

```
$viewFile = 'foo.blade.php';
$html = $bladeService->makeView($viewFile, ['name' => 'John Doe'])->render();
```

#### Render with specific view path

[](#render-with-specific-view-path)

This enables you to temporarily use a specific view path without storing it in the Blade Service.

```
$viewFile = 'foo.blade.php';
$html = $bladeService->makeView($viewFile, ['name' => 'John Doe'], [], 'specific/view/path')->render();
```

### Register a custom directive

[](#register-a-custom-directive)

```
$bladeService->registerDirective('datetime', function ($expression) {
    return "";
});

// The directive can now be used by adding the @datetime directive to a view file.
```

### Register a component

[](#register-a-component)

```
$bladeService->registerComponent('foo', function ($view) {
    $view->with('name', 'John Doe');
});

// The component can now be used by adding @component('foo')@endcomponent to a view file.
```

### Register a component directive

[](#register-a-component-directive)

If you have already registered a component. That component can be added as a directive by doing the following:

```
$bladeService->registerComponentDirective('componentname', 'directivename');

// This will register a directive that can be used by adding @directivename()@enddirectivename to a view file, and it will output the component.
```

### Add additional view file paths

[](#add-additional-view-file-paths)

If you need to add more view file paths after initializing the Blade Service, this can be done by calling `BladeService::addViewPath`

```
$bladeService->addViewPath('extra/view/path');
```

#### Prepend view file paths

[](#prepend-view-file-paths)

If you need to add more view file paths before the existing view file paths, this can be done by calling `BladeService::prependViewPath` with the second parameter set to `true`.

```
$bladeService->prependViewPath('extra/view/path', true);
```

Important

For every unique view path added, performance will be affected. This is due to the fact that the Blade Service will have to search through all view paths to find the correct view file. Therefore, it is recommended to add as few view paths as possible.

Error handling
--------------

[](#error-handling)

This package offers a convenient solution for swiftly addressing issues that arise within a function called in a view or a syntax error directly within a file. It provides a function to visually display the error, which proves particularly useful during the development process. To optimize development speed and efficiency, it's advisable to implement an error handler when invoking makeView, ensuring smooth troubleshooting whenever errors occur.

```
try {
    return $bladeService->makeView($viewFile, ['name' => 'John Doe'], [], 'specific/view/path')->render();
} catch (Throwable $e) {
    $bladeService->errorHandler($e)->print();
}
```

Testing
-------

[](#testing)

### Unit tests

[](#unit-tests)

```
composer test
```

### Code coverage

[](#code-coverage)

```
composer test:coverage
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.2% 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 ~36 days

Recently: every ~24 days

Total

13

Last Release

721d ago

Major Versions

1.0.0 → 2.0.02024-01-30

2.0.0 → 3.0.12024-02-13

PHP version history (3 changes)1.0.0PHP 5.6.\*|7.\*|8.\*

2.0.0PHP ^8.3

3.0.1PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f46fe64973c3e89d15c745c0bf601c25983bafea81d30e64d4bf813a6f8c8c7c?d=identicon)[sebastianthulin](/maintainers/sebastianthulin)

---

Top Contributors

[![thorbrink](https://avatars.githubusercontent.com/u/1064724?v=4)](https://github.com/thorbrink "thorbrink (46 commits)")[![sebastianthulin](https://avatars.githubusercontent.com/u/797129?v=4)](https://github.com/sebastianthulin "sebastianthulin (5 commits)")

---

Tags

bladelaravelphp7php8laravelbladetemplatesengine

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/helsingborg-stad-blade/health.svg)

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

###  Alternatives

[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[spatie/laravel-blade-comments

Add debug comments to your rendered output

177325.5k](/packages/spatie-laravel-blade-comments)[radic/blade-extensions

Laravel package providing additional Blade extensions: foreach (with $loop data like twig), break, continue, set,array (multiline), etc

271321.7k5](/packages/radic-blade-extensions)[san-kumar/laravel-crud

Laravel CRUD generator: Generate CRUD for any db table with the crud:generate command.

564.4k](/packages/san-kumar-laravel-crud)

PHPackages © 2026

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