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

ActiveNixphp-plugin[Templating &amp; Views](/categories/templating)

nixphp/view
===========

NixPHP View Plugin with simple templating.

v0.1.1(2mo ago)0114↓50%1MITPHPPHP &gt;=8.3CI passing

Since Nov 30Pushed 2mo ago1 watchersCompare

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

READMEChangelog (2)Dependencies (3)Versions (5)Used By (1)

[![Logo](https://camo.githubusercontent.com/075b2860e9651b98b8c190a8296595c54cff6900890d9e494f31131145e98a6f/68747470733a2f2f6e69787068702e6769746875622e696f2f646f63732f6173736574732f6e69787068702d6c6f676f2d736d616c6c2d7371756172652e706e67)](https://camo.githubusercontent.com/075b2860e9651b98b8c190a8296595c54cff6900890d9e494f31131145e98a6f/68747470733a2f2f6e69787068702e6769746875622e696f2f646f63732f6173736574732f6e69787068702d6c6f676f2d736d616c6c2d7371756172652e706e67)

[![NixPHP View Plugin](https://github.com/nixphp/view/actions/workflows/php.yml/badge.svg)](https://github.com/nixphp/view/actions/workflows/php.yml)

[← Back to NixPHP](https://github.com/nixphp/framework)

---

nixphp/view
===========

[](#nixphpview)

> **A lightweight, native PHP templating system — with layout inheritance and block support.**

This plugin brings a clean, minimal templating system to your NixPHP application. It lets you define base layouts, use content blocks, and safely output user data — all with pure PHP.

> 🧩 Part of the official NixPHP plugin collection. Install it when you need structured HTML rendering — without external engines like Twig or Blade.

---

📦 Features
----------

[](#-features)

- ✅ Define layouts and reuse views via `setLayout()` and `block()/endblock()`
- ✅ Render views with `view('template', [...])`
- ✅ Return response objects with `render('template', [...])`
- ✅ Safe output via `s()` (escape helper)
- ✅ Fully native PHP – no new syntax or templating engine required

---

📥 Installation
--------------

[](#-installation)

```
composer require nixphp/view
```

The plugin auto-registers itself and adds the `view()`, `render()`, `assets()` and `s()` helpers globally.

---

🚀 Usage
-------

[](#-usage)

### 🧱 Rendering views

[](#-rendering-views)

Use the `view()` helper to render a template and return the result as a **string**:

```
$content = view('hello', ['name' => 'World']);
```

This is useful if you want to process or wrap the HTML manually.

Use the `render()` helper to return a **response object** instead (e.g. in your controller):

```
return render('hello', ['name' => 'World']);
```

This renders the view **and wraps it in a proper response**, ready to be returned from any route handler.

To load a template file in another folder, you can use the dot notation:

```
return render('pages.hello', ['name' => 'World']);
```

Or even multiple levels:

```
return render('pages.elements.hello', ['name' => 'World']);
```

This works for both `view()` and `render()`.

---

### 🧩 Layouts &amp; Blocks

[](#-layouts--blocks)

Use `setLayout()` to define a parent layout, and `block()/endblock()` to inject content:

#### `views/page.phtml`

[](#viewspagephtml)

```
