PHPackages                             ez-php/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. [Framework](/categories/framework)
4. /
5. ez-php/view

ActiveLibrary[Framework](/categories/framework)

ez-php/view
===========

PHP template engine for the ez-php framework — layouts, sections, partials, and HTML escaping

1.11.1(1mo ago)00MITPHPPHP ^8.5CI passing

Since Mar 22Pushed 1mo agoCompare

[ Source](https://github.com/ez-php/view)[ Packagist](https://packagist.org/packages/ez-php/view)[ Docs](https://github.com/ez-php/view)[ RSS](/packages/ez-php-view/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (16)Versions (34)Used By (0)

ez-php/view
===========

[](#ez-phpview)

PHP template engine for the ez-php framework. Renders `.php` template files with layout inheritance, named sections, reusable partials, and HTML escaping — no external library required.

---

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

[](#installation)

```
composer require ez-php/view
```

---

Quick Start
-----------

[](#quick-start)

Register the provider in `provider/modules.php`:

```
use EzPhp\View\ViewServiceProvider;

$app->register(ViewServiceProvider::class);
```

Add config to `config/view.php`:

```
return [
    'path' => env('VIEW_PATH', base_path('resources/views')),
];
```

Render a template from a controller:

```
use EzPhp\View\View;

return new Response(View::render('home', ['name' => 'Alice']));
```

---

Template Files
--------------

[](#template-files)

Templates are plain PHP files stored in `resources/views/` (or the configured path).

```
resources/views/
├── layouts/
│   └── app.php
├── partials/
│   └── nav.php
└── home.php

```

Template names use **dot-notation** as directory separators:

- `'home'` → `views/home.php`
- `'layouts.app'` → `views/layouts/app.php`
- `'users.profile'` → `views/users/profile.php`

---

Template API
------------

[](#template-api)

Inside every template file, `$this` refers to a `TemplateContext` that exposes:

### `$this->e(string $value): string`

[](#this-estring-value-string)

HTML-escape a value. Always use for user-supplied data.

```
Hello, !
```

### `$this->extends(string $template): void`

[](#this-extendsstring-template-void)

Declare that this template extends a layout.

```
