PHPackages                             initphp/views - 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. initphp/views

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

initphp/views
=============

A small, adapter-based view rendering layer for PHP with PurePHP, Blade and Twig back-ends.

2.0.0(3w ago)0461MITPHPPHP &gt;=8.0CI passing

Since Jan 14Pushed 3w ago1 watchersCompare

[ Source](https://github.com/InitPHP/Views)[ Packagist](https://packagist.org/packages/initphp/views)[ RSS](/packages/initphp-views/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (7)Versions (5)Used By (1)

InitPHP Views
=============

[](#initphp-views)

A small, adapter-based view rendering layer for PHP. Write your application against one tiny interface and render with plain PHP, [Blade](https://laravel.com/docs/blade)or [Twig](https://twig.symfony.com/) — switching engines is a one-line change.

[![CI](https://github.com/InitPHP/Views/actions/workflows/ci.yml/badge.svg)](https://github.com/InitPHP/Views/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/bf6e4632107a394454aaf31554efae5c4133e6158094455bdf482b0e42eabe0c/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f76696577732f76)](https://packagist.org/packages/initphp/views) [![Total Downloads](https://camo.githubusercontent.com/0c38dbf79d861f20db13cbb13a46a87a384d3a7fdaf4a92e0e89c69190a779a9/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f76696577732f646f776e6c6f616473)](https://packagist.org/packages/initphp/views) [![License](https://camo.githubusercontent.com/12215a82b029b6deadc4934ab89b8ef948553a45948e85ed5ddfdba8f460f96b/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f76696577732f6c6963656e7365)](https://packagist.org/packages/initphp/views) [![PHP Version Require](https://camo.githubusercontent.com/a1474a6bd9ff72e968ff51a62a001ed1e98e987fac8cfb5bf42d5a0f605a2577/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f76696577732f726571756972652f706870)](https://packagist.org/packages/initphp/views)

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

[](#requirements)

- PHP 8.0 or higher

The bundled adapters need their engine only when you use them:

AdapterClassEngineNeedsPure PHP`InitPHP\Views\Adapters\PurePHPAdapter`Plain `.php` templates— (core only)Blade`InitPHP\Views\Adapters\BladeAdapter`Laravel Blade[`illuminate/view`](https://packagist.org/packages/illuminate/view)Twig`InitPHP\Views\Adapters\TwigAdapter`Symfony Twig[`twig/twig`](https://packagist.org/packages/twig/twig)Installation
------------

[](#installation)

```
composer require initphp/views
```

Then install the engine for the adapter you want (skip this for the Pure PHP adapter):

```
composer require illuminate/view   # for BladeAdapter
composer require twig/twig         # for TwigAdapter
```

Quick start
-----------

[](#quick-start)

Register an adapter once through the `View` facade, then render from anywhere with the global `view()` helper.

```
require 'vendor/autoload.php';

use InitPHP\Views\Facade\View;
use InitPHP\Views\Adapters\PurePHPAdapter;

View::via(new PurePHPAdapter(__DIR__ . '/views'));

echo view('dashboard', ['username' => 'admin']);
```

`views/dashboard.php`:

```
Welcome,
```

### Rendering multiple views

[](#rendering-multiple-views)

Pass a list of names to render them in order and concatenate the output:

```
echo view(['header', 'content', 'footer'], ['title' => 'Home']);
```

### Passing data

[](#passing-data)

`$data` is an associative array, or an object whose public properties are used:

```
$user = new stdClass();
$user->username = 'admin';

echo view('profile', $user);
```

The `view()` helper and the `View` facade
-----------------------------------------

[](#the-view-helper-and-the-view-facade)

The `view()` helper is a thin wrapper over the facade:

```
function view(string|array $views, array|object $data = []): string;
```

It queues the views, attaches the data and renders — equivalent to:

```
echo View::setView('header', 'footer')->setData(['title' => 'Home'])->render();
```

Every call you make on `View` is forwarded to the registered adapter:

CallReturnsPurpose`View::via(string|ViewAdapterInterface $adapter)``void`Register the adapter that backs the facade.`View::setView(string ...$views)`adapterQueue one or more views, in order.`View::setData(array|object $data)`adapterMerge data exposed to the views.`View::getData(?string $key = null, mixed $default = null)``mixed`Read merged data (or everything when `$key` is `null`).`View::render()``string`Render the queue and return the output.`View::via()` accepts a ready-made adapter instance, or the class name of an adapter that can be built with no constructor arguments. Calling the facade before an adapter is registered throws a `ViewException`.

Adapters
--------

[](#adapters)

### Pure PHP adapter

[](#pure-php-adapter)

Renders ordinary `.php` files. The `.php` extension is added automatically when missing, and each file is evaluated in an isolated scope: it receives the data as local variables and has **no** access to the adapter instance (`$this`).

```
use InitPHP\Views\Facade\View;
use InitPHP\Views\Adapters\PurePHPAdapter;

View::via(new PurePHPAdapter(__DIR__ . '/views'));

echo view('dashboard/index', ['username' => 'admin']);
```

A missing view file throws a `ViewException`.

### Blade adapter

[](#blade-adapter)

Bootstraps a standalone Blade engine — no full Laravel application required. Install `illuminate/view` first.

```
use InitPHP\Views\Facade\View;
use InitPHP\Views\Adapters\BladeAdapter;

View::via(new BladeAdapter(__DIR__ . '/views', __DIR__ . '/cache'));

echo view('dashboard', ['username' => 'admin']);
```

Both directories must exist. The first argument may also be an array of template directories. Register custom directives and conditionals on the adapter instance:

```
$blade = new BladeAdapter(__DIR__ . '/views', __DIR__ . '/cache');
View::via($blade);

$blade->directive('datetime', static function (string $expression): string {
    return "";
});

$blade->if('admin', static fn ($user): bool => $user->isAdmin());
```

The adapter also exposes the most common factory methods — `make()`, `file()`, `exists()`, `share()`, `composer()`, `creator()`, `addNamespace()` and `replaceNamespace()` — and forwards any other call to the underlying Blade factory. See the [Blade documentation](https://laravel.com/docs/blade).

### Twig adapter

[](#twig-adapter)

Bootstraps a Twig environment. Install `twig/twig` first.

```
use InitPHP\Views\Facade\View;
use InitPHP\Views\Adapters\TwigAdapter;

View::via(new TwigAdapter(__DIR__ . '/views', __DIR__ . '/cache'));

echo view('dashboard.html.twig', ['username' => 'admin']);
```

Both directories must exist. Twig does **not** add a file extension, so include it in the view name. Use `getEnvironment()` to add extensions, globals or filters:

```
$twig = new TwigAdapter(__DIR__ . '/views', __DIR__ . '/cache');
$twig->getEnvironment()->addGlobal('app_name', 'InitPHP');

View::via($twig);
```

Exceptions
----------

[](#exceptions)

All exceptions implement `InitPHP\Views\Exceptions\ViewExceptionInterface`, so a single `catch` can handle every failure this package raises.

ExceptionExtendsThrown when`ViewException``RuntimeException`The facade is used before an adapter is registered, or a view file is missing.`ViewAdapterException``ViewException``View::via()` is given an invalid adapter.`ViewInvalidArgumentException``InvalidArgumentException`A view or cache directory does not exist.```
use InitPHP\Views\Exceptions\ViewExceptionInterface;

try {
    echo view('dashboard', $data);
} catch (ViewExceptionInterface $e) {
    // handle any InitPHP Views failure
}
```

Custom adapters
---------------

[](#custom-adapters)

Implement `InitPHP\Views\Interfaces\ViewAdapterInterface` (or extend `AdapterAbstract`, which already handles queueing and data) and register it with `View::via()`. See [docs/custom-adapter.md](docs/custom-adapter.md).

Documentation
-------------

[](#documentation)

Full developer documentation lives in [`docs/`](docs/):

- [Getting started](docs/getting-started.md)
- [The facade and the `view()` helper](docs/facade-and-helper.md)
- [Pure PHP adapter](docs/purephp-adapter.md)
- [Blade adapter](docs/blade-adapter.md)
- [Twig adapter](docs/twig-adapter.md)
- [Writing a custom adapter](docs/custom-adapter.md)
- [Exceptions](docs/exceptions.md)

Contributing
------------

[](#contributing)

Bug reports and pull requests are welcome. Please read the org-wide [contribution guide](https://github.com/InitPHP/.github/blob/main/CONTRIBUTING.md)first. Run the full check suite locally before opening a PR:

```
composer ci   # php-cs-fixer (dry-run) + phpstan + phpunit
```

Credits
-------

[](#credits)

- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) &lt;&gt;

License
-------

[](#license)

Released under the [MIT License](./LICENSE). Copyright © 2022 InitPHP.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance95

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

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.

###  Release Activity

Cadence

Every ~622 days

Total

3

Last Release

22d ago

Major Versions

1.x-dev → 2.0.02026-06-11

### Community

Maintainers

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

---

Top Contributors

[![muhammetsafak](https://avatars.githubusercontent.com/u/104234499?v=4)](https://github.com/muhammetsafak "muhammetsafak (5 commits)")

---

Tags

bladeinitphpphpphp-libraryphp8renderingtemplatetemplate-enginetwigviewview-engineviewsphptwigbladetemplateviewtemplate engineviewsRenderinginitphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/initphp-views/health.svg)

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

###  Alternatives

[eftec/bladeone

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

8379.7M104](/packages/eftec-bladeone)[talesoft/tale-pug

A clean, lightweight and easy-to-use templating engine for PHP based on Pug, formerly Jade

319.5k3](/packages/talesoft-tale-pug)[leitsch/kirby-blade

Enable Laravel Blade Template Engine for Kirby 4 and Kirby 5

2110.6k](/packages/leitsch-kirby-blade)[eftec/bladeonehtml

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

1022.8k6](/packages/eftec-bladeonehtml)

PHPackages © 2026

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