PHPackages                             brainlight/brainlight-php - 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. brainlight/brainlight-php

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

brainlight/brainlight-php
=========================

Brainlight template engine for PHP.

v1.3.0(3y ago)0311MITPHPPHP ^8.1

Since Mar 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/GiromettaMarco/brainlight-php)[ Packagist](https://packagist.org/packages/brainlight/brainlight-php)[ Docs](https://github.com/GiromettaMarco/brainlight-php)[ RSS](/packages/brainlight-brainlight-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)DependenciesVersions (10)Used By (1)

Brainlight PHP
==============

[](#brainlight-php)

Brainlight is a lightweight templating system with minimal logic pattern.

This is a PHP implementation of the Brainlight paradigm.

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Additional logic](#additional-logic)
- [Options](#options)
- [License](#license)

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

[](#requirements)

- PHP &gt;= 8.1
- Composer

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

[](#installation)

Require Brainlight Php package in your composer project using the following command:

```
composer require brainlight/brainlight-php

```

Usage
-----

[](#usage)

Create a new Brainlight Engine instance:

```
use Brainlight\BrainlightPhp\Engine;

$engine = new Engine([
    'cacheDir' => __DIR__ . '/cache',
    'templatesDir' => __DIR__,
]);
```

Then render any Brainlight template:

```
echo $engine->render('templateName', [
    'title' => 'Homepage',
]);
```

Make reference to the [Brainlight documentation](https://github.com/GiromettaMarco/brainlight) for templates syntax.

Additional logic
----------------

[](#additional-logic)

Brainlight PHP supports templates with additional logic by making use of the `Brainlight\BrainlightPhp\Logic` class and namespaces.

First consider adding a namespace root in your engine configuration:

```
use Brainlight\BrainlightPhp\Engine;

$engine = new Engine([
    'cacheDir' => __DIR__ . '/cache',
    'templatesDir' => __DIR__,
    'logicNamespace' => 'Logic',
]);
```

Then create a new logic class by extending `Brainlight\BrainlightPhp\Logic`:

```
namespace Logic;

use Brainlight\BrainlightPhp\Logic;

class Button extends Logic
{
    // ...
}
```

This way, while rendering `{{ >+ button }}` and `{{ &+ button }}` class `Logic\Button` will be loaded.

In addition, the template name inside these tags will be converted to a namespace. So `buttons.button-delete` will become `Buttons\ButtonDelete`.

A Logic class must implement the `getVariables()` method:

```
namespace Logic;

use Brainlight\BrainlightPhp\Logic;

class Button extends Logic
{
    protected function getVariables(array $parameters): array
    {
        return $parameters;
    }
}
```

The purpose of this function is to modify the arguments passed to the template. Such arguments are collected inside the `parameters` associative array.

It is possible to set mandatory arguments using the `mandatory` array property and mandatory slots using the `mandatorySlots` array property:

```
namespace Logic\Inclusions;

use Brainlight\BrainlightPhp\Logic;

class Page extends Logic
{
    protected array $mandatory = [
        'title',
    ];

    protected array $mandatorySlots = [
        'content',
    ];

    // ...
}
```

It is also possible to change the default template associated with a logic class by setting its `template` property:

```
namespace Logic;

use Brainlight\BrainlightPhp\Logic;

class Button extends Logic
{
    public ?string $template = 'buttons.custom-template';

    // ...
}
```

To render a template with additional logic directly from a PHP script, use the third parameter of the `render()` function:

```
$engine->render('button', [], true);
```

Options
-------

[](#options)

The Engine constructor supports the following options:

### cacheDir

[](#cachedir)

Type: string

Absolute path where cached templates will be stored.

This field is mandatory.

### templatesDir

[](#templatesdir)

Type: mixed

Absolute path to the directory containing templates. It also accepts an array of paths.

If `false` is provided, the `render()` method will accept a fully qualified filename instead of a template name.

Example:

```
use Brainlight\BrainlightPhp\Engine;

$engine = new Engine([
    'cacheDir' => __DIR__ . '/cache',
    'templatesDir' => false,
]);

echo $engine->render(__DIR__ . '/templateName.brain');
```

Default value: `false`

### partialsDir

[](#partialsdir)

Type: mixed

Absolute path to the directory containing partial templates for inclusions and extensions. It also accepts an array of paths.

If `false` is provided, the template engine will consider the template name of inclusion tags as a fully qualified filename instead of a template name.

If `null` is provided, partial templates will be resolved according to the same rule set with `'templatesDir'`.

Default value: `null`

### logicNamespace

[](#logicnamespace)

Type: string|bool

Namespace root used to resolve additional logic classes.

Default value: `false`

### extension

[](#extension)

Type: string

The Brainlight template file extension.

Default value: `'brain'`

### Escaping options

[](#escaping-options)

The following options (with default value) are applied to any escape operation performed with the PHP function [htmlspecialchars](https://www.php.net/manual/en/function.htmlspecialchars.php):

```
[
    'escapeFlags' => ENT_QUOTES,
    'escapeEncoding' => 'UTF-8',
    'escapeDoubleEncode' => true,
]
```

License
-------

[](#license)

Brainlight PHP is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~3 days

Total

9

Last Release

1143d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1666c97dcce04d0845da98d085f90ea97428b35382f0585ea2a3d56fc06c6419?d=identicon)[Girometta Marco](/maintainers/Girometta%20Marco)

---

Top Contributors

[![GiromettaMarco](https://avatars.githubusercontent.com/u/14976285?v=4)](https://github.com/GiromettaMarco "GiromettaMarco (27 commits)")

---

Tags

phptemplatingbrainlight

### Embed Badge

![Health badge](/badges/brainlight-brainlight-php/health.svg)

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

###  Alternatives

[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8208.4M87](/packages/eftec-bladeone)[goetas/twital

PHP templating engine that combines Twig and PHPTal power points

12813.1k1](/packages/goetas-twital)[goetas/twital-bundle

Twital templating engine Symfony Bundle

206.8k](/packages/goetas-twital-bundle)[eftec/bladeonehtml

The standalone version Blade Template Engine from Laravel in a single php file

1018.1k5](/packages/eftec-bladeonehtml)

PHPackages © 2026

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