1. Go to this page and download the library: Download scorninpc/slim-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/ */
scorninpc / slim-smarty-view example snippets
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
/ Set view in Container
$container->set("view", function($container) {
// Create smarty view
$view = new \Slim\Views\Smarty(
[
'template_dir' => [__DIR__ . "/templates"], // Where to put .tpl files
'compile_dir' => __DIR__ . "/templates_c", // Where to save compiled
'cache_dir' => __DIR__ . "/templates_c", // Where to cache
'caching' => FALSE, // Enable usa of cache
'cache_lifetime' => 4600, // Time for cache
'force_compile' => TRUE, // Force to compile .tpl all the time (compile .tpl every time . this is slow for production)
'debugging' => FALSE, // Enable debug console
'compile_check' => TRUE, // Enable check if need compile (this will check timestamp of file and compile again. set to false for performance)
]
);
return $view;
});
// Route
$app->get('/', function (Request $request, Response $response, $args) {
return $this->get('view')->render($response, 'index.tpl', [
'variable' => "Hello!",
]);
});
// Run
$app->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.