PHP code example of mattmezza / slim-handlebars-view

1. Go to this page and download the library: Download mattmezza/slim-handlebars-view 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/ */

    

mattmezza / slim-handlebars-view example snippets


// Create Slim app
$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register Twig View helper
$container['view'] = new \Slim\Views\Handlebars(
    'path/to/templates',
    'partials',
    [
        'extension' => 'hbs' // default is html
    ]);

// Define named route
$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->view->render($response, 'profile', [
        'name' => $args['name']
    ]);
})->setName('profile');

// Run app
$app->run();