PHPackages                             peak/view - 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. peak/view

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

peak/view
=========

PHP minimalist view template engine with macros and helpers.

1.1.0(6y ago)141MITPHPPHP &gt;=7.2

Since Jun 20Pushed 5y ago1 watchersCompare

[ Source](https://github.com/peakphp/view)[ Packagist](https://packagist.org/packages/peak/view)[ RSS](/packages/peak-view/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

[![Peak](https://raw.githubusercontent.com/peakphp/art/master/logo-clean-50x50.png)](https://raw.githubusercontent.com/peakphp/art/master/logo-clean-50x50.png) Peak/View
=========================================================================================================================================================================

[](#-peakview)

[![version](https://camo.githubusercontent.com/429f0aa817b5e822fe7f8ae8ca6eeda4412a74805b26ea32edf5e266303a255c/68747470733a2f2f706f7365722e707567782e6f72672f7065616b2f766965772f76657273696f6e)](https://packagist.org/packages/peak/view)[![License](https://camo.githubusercontent.com/bbbb57a3f4645b4ce4ac7b11a0bdada5ecd2a22d4209ba04b6661f5e925e6f6e/68747470733a2f2f706f7365722e707567782e6f72672f7065616b2f766965772f6c6963656e7365)](https://github.com/peakphp/view/blob/master/LICENSE.md)

Fast and minimalist view template engine with macro, helpers and directives.

! Deprecated
------------

[](#-deprecated)

This package is mark as deprecated! It may receive bug fixes if needed but that's it. I strongly encourage users to switch to a modern JS front framework instead of using PHP as templating engine.

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

[](#installation)

This is a standalone package and not provided automatically with `peak/framework`

```
$ composer require peak/view

```

Basic usage
-----------

[](#basic-usage)

A view need at least 2 things:

- A Presentation
- Data (or variables if you prefer)

```
$presentation = new SingleLayoutPresentation(
    '/path/to/layout1.php',
    '/path/to/view1.php'
);
$data = [
    'title' => 'FooTheBar',
    'name' => 'JohnDoe'
];
$view = new View($data, $presentation);
```

### Example of view templates

[](#example-of-view-templates)

layout example:

```

    title ?>

        layoutContent ?>

```

script example (represented by `$this->layoutContent` in your layout):

```

    hello name ?>

```

### Render a view

[](#render-a-view)

```
$output = $view->render();
```

### Create a complex Presentation

[](#create-a-complex-presentation)

```
$presentation = new Presentation([
    '/layout1.php' => [
        '/view1.php',
        '/layout2,php' => [
            '/view2.php',
            '/view3.php',
        ]
    ]
]);
```

Macros
------

[](#macros)

Macro are closure that will be bind to your view class instance. They have access to all class properties/methods so they must be used carefully. Macro are ideal for small task.

```
$view->addMacro('formatedName', function() {
    return ucfirst($this->name);
});
```

and in your template view:

```
...
Hello
```

Helpers
-------

[](#helpers)

An helper is a standalone object instance that is `callable`. In contrary of macro, helper do not have access to view properties/methods directly but tend to be more maintainable and secure than macro. Helper are ideal for advanced task and can benefit from dependencies injection.

Example of an helper class:

```
class EscapeTextHelper
{
    public function __invoke($text)
    {
        return filter_var($text, FILTER_SANITIZE_SPECIAL_CHARS);
    }
}
```

Before you can use it, you'll need to give a function name to your view helper:

```
$view->setHelpers([
    'escape' => new EscapeTextHelper(),
    // ...
]);
```

and finally, you'll be able to use your helper the same way you use macros

```
...
Hello
```

Directives
----------

[](#directives)

Directives provide you a simpler and more elegant syntax for writing templates. By default, there is no directive activated in your View. You need to add them to your View instance with `setDirectives()` method. The downside of directives is that View must run them after rendering a template, adding an extra compilation step. The more directives you have, the more it take times to render the view . Of course, this side effect can be mitigated with a proper caching solution, but to keep things simple, Peak View doesn't provide one by default.

```
$view->setDirectives([
    // give you ability to print variable with syntax {{ $myVar }}
    new EchoDirective(),
    // give you ability to call native php functions,
    // macros or helpers with syntax @function(...args)
    new FnDirective(),
]);

$view->addVars([
    'name' => 'bob'
    'messages' => [
        // ...
    ],
    'items' => [
        'property' => 'value'
    ]
]);
```

template.php

```
Hello {{ $name }}

You can call native php function with @
@date(l \t\h\e jS) - You have @count($messages) message(s)

You can also call helpers and macros too
@escape($name)

You can still use directly PHP like this: name; ?>

And finally, array variable can be accessed with DotNotation syntax: {{ $items.property }}
```

It is important to keep in mind that PHP is executed first in your template and directives are compiled/rendered after that.

You can also write you own directive by using `DirectiveInterface`.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~315 days

Total

2

Last Release

2206d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1209308?v=4)[François Lajoie](/maintainers/1franck)[@1franck](https://github.com/1franck)

---

Top Contributors

[![1franck](https://avatars.githubusercontent.com/u/1209308?v=4)](https://github.com/1franck "1franck (2689 commits)")

---

Tags

peakphptemplate-enginetemplateviewmacropeak

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/peak-view/health.svg)

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

###  Alternatives

[eftec/bladeone

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

8208.4M87](/packages/eftec-bladeone)[jenssegers/blade

The standalone version of Laravel's Blade templating engine for use outside of Laravel.

8661.2M109](/packages/jenssegers-blade)[wyrihaximus/twig-view

Twig powered View for CakePHP

804.7M1](/packages/wyrihaximus-twig-view)[anourvalar/office

Generate documents from existing Excel &amp; Word templates | Export tables to Excel (Grids)

24085.2k](/packages/anourvalar-office)[ytake/laravel-smarty

Smarty template engine for Laravel and Lumen

87401.6k](/packages/ytake-laravel-smarty)[aura/view

Provides an implementation of the TemplateView and TwoStepView patterns, with support for helpers and for closures as templates, using PHP itself as the templating language.

88152.8k19](/packages/aura-view)

PHPackages © 2026

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