scorninpc / slim-smarty-view
Slim Framework 4 view helper built on top of the Smarty templating component
2.0.6
2023-07-06 12:00 UTC
Requires
- php: ^7.3 || ^8.0
- php-di/php-di: ^6.3
- slim/slim: ^4.0
- smarty/smarty: ^4.0
Requires (Dev)
- phpunit/phpunit: ^8.5.13 || ^9.3.8
README
This is a Slim Framework 4 view helper built on top of the Smarty templating component. You can use this component to create and render templates in your Slim Framework 4 application.
How to install
Via Composer
$ composer require scorninpc/slim-smarty-view "2.*"
Example
<?php use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; require __DIR__ . '/vendor/autoload.php'; // Create Container $container = new \DI\Container(); AppFactory::setContainer($container); // Create the app $app = AppFactory::create(); // 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();
Credits
This project is only a fork to add examples and the package on packagist to work with composer, all credits of this nice rework are from Matheus Marques
License
The MIT License (MIT). Please see License File for more information.