PHPackages                             uniibu/better-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. [Templating &amp; Views](/categories/templating)
4. /
5. uniibu/better-php-view

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

uniibu/better-php-view
======================

Render PHP view scripts into a PSR-7 Response object.

110PHP

Since Apr 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/uniibu/Better-PHP-View)[ Packagist](https://packagist.org/packages/uniibu/better-php-view)[ RSS](/packages/uniibu-better-php-view/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/398c7b90356a0f321f67a76543484a612807503ce57ca3c6b65d4f3b0617c3fb/68747470733a2f2f7472617669732d63692e6f72672f676567676c65746f2f5048502d566965772e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/geggleto/PHP-View)

Better-PHP-View
---------------

[](#better-php-view)

This is a renderer for rendering PHP view scripts into a PSR-7 Response object. It works well with Slim Framework 3.

This Version
------------

[](#this-version)

This version is a fork from the original PHP-view

This version also adds optional escaping using zend-escaper () and the ability to include other views using $PHPview-&gt;fetch('TEMPLATE NAME');

Included templates must reside on the same template directory.

Included templates also has access to the attributes passed on the main template.

To use the escape function, just add the type of escaping when calling $PHPview-&gt;render ex. $PHPview-&gt;render($response,'template.php',\['args' =&gt; 'value'\],'html')

If escape type is left out, nothing will be escaped. It will only escape the values of the associative arrays.

### Cross-site scripting (XSS) risks (optional on this version)

[](#cross-site-scripting-xss-risks-optional-on-this-version)

Note that PHP-View has no built-in mitigation from XSS attacks. It is the developer's responsibility to use `htmlspecialchars()` or a component like [zend-escaper](https://github.com/zendframework/zend-escaper). Alternatively, consider [Twig-View](https://github.com/slimphp/Twig-View).

Templates
---------

[](#templates)

You may use `$this` inside your php templates. `$this` will be the actual PhpRenderer object will allow you to render sub-templates

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

[](#installation)

Install with [Composer](http://getcomposer.org):

```
composer require uniibu/better-php-view:dev-master

```

Usage with Slim 3 (this version)
--------------------------------

[](#usage-with-slim-3-this-version)

```
use Slim\Views\PhpRenderer;

include "vendor/autoload.php";

$app = new Slim\App();
$container = $app->getContainer();
$container['renderer'] = new PhpRenderer("./templates");

$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->renderer->render($response, "/hello.php", $args, 'html');
});

$app->run();
```

Usage with any PSR-7 Project
----------------------------

[](#usage-with-any-psr-7-project)

```
//Construct the View
$phpView = new PhpRenderer("./path/to/templates");

//Render a Template
$response = $phpView->render(new Response(), "/path/to/template.php", $yourData, 'html');
```

Escaping Options (this version) check  for reference
---------------------------------------------------------------------------------------------------

[](#escaping-options-this-version-check-httpsgithubcomzendframeworkzend-escaper-for-reference)

> 'html' = zend-&gt;escapeHtml

> 'attr' = zend-&gt;escapeHtmlAttr

> 'url' = zend-&gt;escapeUrl

> 'js' = zend-&gt;escapeJs

> 'css' = zend-&gt;escapeCss

Template Variables (this version)
---------------------------------

[](#template-variables-this-version)

You can now add variables and escape type to your renderer that will be available to all templates you render.

```
// via the constructor
$templateVariables = [
    "title" => "Title"
];
$phpView = new PhpRenderer("./path/to/templates", $templateVariables, 'html');

// or setter
$phpView->setAttributes($templateVariables);

// or individually
$phpView->addAttribute($key, $value);
```

Data passed in via `->render()` takes precedence over attributes.

```
$templateVariables = [
    "title" => "Title"
];
$phpView = new PhpRenderer("./path/to/templates", $templateVariables, 'js');

//...

$phpView->render($response, $template, [
    "title" => "My Title"
], 'attr');
// In the view above, the $title will be "My Title" and not "Title"
```

Exceptions
----------

[](#exceptions)

`\RuntimeException` - if template does not exist

`\InvalidArgumentException` - if $data contains 'template'

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11394857?v=4)[Uni Sayo](/maintainers/uniibu)[@uniibu](https://github.com/uniibu)

---

Top Contributors

[![uniibu](https://avatars.githubusercontent.com/u/11394857?v=4)](https://github.com/uniibu "uniibu (7 commits)")

### Embed Badge

![Health badge](/badges/uniibu-better-php-view/health.svg)

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

###  Alternatives

[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3861.2M](/packages/limenius-react-bundle)[area17/laravel-auto-head-tags

Laravel Auto Head Tags helps you build the list of head elements for your app

4616.0k](/packages/area17-laravel-auto-head-tags)[jelix/wikirenderer

WikiRenderer is a library to generate HTML or anything else from wiki content.

1712.2k1](/packages/jelix-wikirenderer)[webkinder/sproutset

A Composer package for handling responsive images in Roots Bedrock + Sage + Blade projects.

281.8k](/packages/webkinder-sproutset)

PHPackages © 2026

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