PHP code example of maps82 / smarty-view

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

    

maps82 / smarty-view example snippets


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

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

// Register Smarty View helper
$container['view'] = function ($c) {
    $view = new \Slim\Views\Smarty('path/to/templates', [
        'compile' => 'path/to/compile',
        'config' => 'path/to/config', // optional
        'cache' => 'path/to/cache', // optional - omit this to disable caching
        'debug' => false
    ]);
    
    // Instantiate and add Slim specific extension
    $view->addExtension(new Slim\Views\SmartyExtension(
        $c['router'],
        $c['request']->getUri()
    ));

    return $view;
};

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

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