PHP code example of template-interop / middleware

1. Go to this page and download the library: Download template-interop/middleware library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

template-interop / middleware example snippets


$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);



use Interop\Template\Middleware\TemplateEngine;
use Psr\Http\Message\ServerRequestInterface;

new TemplateEngine($twig, $streamFactory, 'tpl_name', 'tpl_params');