PHPackages                             geggleto/slim-renderer - 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. geggleto/slim-renderer

Abandoned → [https://github.com/slimphp/PHP-View](/?search=https%3A%2F%2Fgithub.com%2Fslimphp%2FPHP-View)Library[Framework](/categories/framework)

geggleto/slim-renderer
======================

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

3.1.0(5y ago)2202461MITPHPPHP ^7.3 || ^8.0CI passing

Since Sep 29Pushed 6mo ago13 watchersCompare

[ Source](https://github.com/geggleto/slim-renderer)[ Packagist](https://packagist.org/packages/geggleto/slim-renderer)[ RSS](/packages/geggleto-slim-renderer/feed)WikiDiscussions 3.x Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (20)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6a67d963303f923ffbe084fdcc6333d304e924d07a0fa4b60c2d8a50a97b28b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f736c696d7068702f7068702d766965772e737667)](https://packagist.org/packages/slim/PHP-View)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE.md)[![Build Status](https://github.com/slimphp/PHP-View/actions/workflows/tests.yml/badge.svg?branch=3.x)](https://github.com/slimphp/PHP-View/actions)[![Total Downloads](https://camo.githubusercontent.com/0f30284f931479401ca318add388bef47c3c20562dc032c436526923a1826a78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736c696d2f5048502d566965772e737667)](https://packagist.org/packages/slim/PHP-View/stats)

PHP Renderer
------------

[](#php-renderer)

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

### Cross-site scripting (XSS) risks

[](#cross-site-scripting-xss-risks)

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 [laminas-escaper](https://github.com/laminas/laminas-escaper). Alternatively, consider [Twig-View](https://github.com/slimphp/Twig-View).

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

[](#installation)

```
composer require slim/php-view

```

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

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

```
//Construct the View
$renderer = new PhpRenderer('path/to/templates');

$viewData = [
    'key1' => 'value1',
    'key2' => 'value2',
];

// Render a template
$response = $renderer->render(new Response(), 'hello.php', $viewData);
```

Usage with Slim 4
-----------------

[](#usage-with-slim-4)

```
use Slim\AppFactory;
use Slim\Views\PhpRenderer;

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

$app = AppFactory::create();

$app->get('/hello', function ($request, $response) {
    $renderer = new PhpRenderer('path/to/templates');

    $viewData = [
        'name' => 'John',
    ];

    return $renderer->render($response, 'hello.php', $viewData);
});

$app->run();
```

DI Container Setup
------------------

[](#di-container-setup)

You can place the `PhpRenderer` instantiation within your DI Container.

```
