PHPackages                             template-interop/middleware - 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. template-interop/middleware

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

template-interop/middleware
===========================

PSR-15 HTTP middleware for template-interop/engine

0.0.2(6y ago)06MITPHPPHP &gt;=7.0

Since Sep 17Pushed 6y agoCompare

[ Source](https://github.com/template-interop/middleware)[ Packagist](https://packagist.org/packages/template-interop/middleware)[ RSS](/packages/template-interop-middleware/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

template-interop/middleware
===========================

[](#template-interopmiddleware)

PSR-15 middleware to build a view for a response thanks to any template engine.

Compatible engines:

- Twig
- Latte
- Mustache
- Smarty
- Plates
- Blade
- Dwoo
- Div
- Foil
- Stamp

Requirements
------------

[](#requirements)

- PHP &gt;= 7.0
- A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
- A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)

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

[](#installation)

This package is installable and autoloadable via Composer as [template-interop/middleware](https://packagist.org/packages/template-interop/middleware).

```
composer require template-interop/middleware
```

Usage
-----

[](#usage)

```
$dispatcher = new Dispatcher([
    new TemplateEngine($twig, $streamFactory),
    new Router([
        'GET /hello/{name}' => function(ServerRequestInterface $request) {
            return (new Response(200))
                ->withAttribute('template-name', 'hello')
                ->withAttribute('template-parameters', ['name' => $request->getAttribute('name')])
            ;
        }
    ])
]);
$response = $dispatcher->dispatch(new ServerRequest);
```

Request attributes names are configurable:

```
