template-interop / middleware
PSR-15 HTTP middleware for template-interop/engine
0.0.2
2019-09-17 19:51 UTC
Requires
- php: >=7.0
- psr/http-factory: ^1.0
- psr/http-server-middleware: ^1.0
- template-interop/engine: ^0.0.2
This package is auto-updated.
Last update: 2024-11-18 07:55:51 UTC
README
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
- PHP >= 7.0
- A PSR-7 http library
- A PSR-15 middleware dispatcher
Installation
This package is installable and autoloadable via Composer as template-interop/middleware.
composer require template-interop/middleware
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:
<?php use Interop\Template\Middleware\TemplateEngine; use Psr\Http\Message\ServerRequestInterface; new TemplateEngine($twig, $streamFactory, 'tpl_name', 'tpl_params');
Contains the following options to configure the json_decode function: