PHP code example of andrewslince / slim3-mustache-view

1. Go to this page and download the library: Download andrewslince/slim3-mustache-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/ */

    

andrewslince / slim3-mustache-view example snippets




$app = new \Slim\App([
    // your application settings
]);

// get application container
$container = $app->getContainer();

// register view template engine and configurations
$container['renderer'] = function () {
    return new \Slim\Views\Mustache([

        // REQUIRED
        'template' => [

            // REQUIRED
            'paths' => [
                realpath('./templates')
            ],

            // optional
            'extension' => 'html',

            // optional
            'charset' => 'utf-8',
        ],

        // put other mustache options here¹
    ]);
};

// use the render() method in your application routes
$app->get('/', function ($request, $response, $args) {

    // render your view
    return $this->renderer->render(
        $response,
        'index',
        $args
    );
});

$app->run();