ytake / laravel-smarty
Smarty template engine for Laravel and Lumen
Fund package maintenance!
ytake
Installs: 327 554
Dependents: 1
Suggesters: 1
Security: 0
Stars: 84
Watchers: 9
Forks: 24
Open Issues: 6
Requires
- php: ^8.1
- illuminate/config: ^10.0|^11.0
- illuminate/console: ^10.0|^11.0
- illuminate/events: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- illuminate/view: ^10.0|^11.0
- smarty/smarty: ^4.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.14
- pdepend/pdepend: ^2.12
- phploc/phploc: *
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5.10|^10.5
- predis/predis: ^2.1
- sebastian/phpcpd: *
- slevomat/coding-standard: ^8.8
- squizlabs/php_codesniffer: ^3.7
- symfony/console: ^6.0|^7.0
- symfony/framework-bundle: ^6.0|^7.0
Suggests
- ext-memcached: memcached Template Cache Driver
- predis/predis: Redis Template Cache Driver
- dev-main
- 8.0.0
- 7.0.1
- 7.0.0
- 6.0.0
- 5.1.0
- 5.0.0
- 4.0.0
- 3.0.1
- 3.0.0
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.12
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- dev-patch-for-laravel7
- dev-feature/patch-for-laravel6
- dev-master-5.0
- dev-master-4.2
- dev-master-4.1
- dev-develop-4.1
This package is auto-updated.
Last update: 2024-12-04 14:35:51 UTC
README
Smarty Template Engine for Laravel
(Support for Laravel5.x - Laravel8.x and Lumen)
Installation For Laravel
Require this package with Composer
$ composer require ytake/laravel-smarty
or composer.json
"require": { "ytake/laravel-smarty": "^6.0" },
Supported Auto-Discovery(^Laravel5.5)
add Laravel.Smarty Service Providers
your config/app.php
'providers' => [ // add smarty extension Ytake\LaravelSmarty\SmartyServiceProvider::class, // add artisan commands Ytake\LaravelSmarty\SmartyConsoleServiceProvider::class, ]
Installation For Lumen
Require this package with Composer
$ composer require ytake/laravel-smarty
or composer.json
"require": { "ytake/laravel-smarty": "~2.0" },
register Laravel.Smarty Service Providers
your bootstrap/app.php
$app->configure('ytake-laravel-smarty'); $app->register(Ytake\LaravelSmarty\SmartyServiceProvider::class); $app->register(Ytake\LaravelSmarty\SmartyConsoleServiceProvider::class);
Configuration
publish configuration file (for Laravel5)
$ php artisan vendor:publish
publish to config directory
Of Course, Blade Template can also be used to Render Engine.
configuration file (for Lumen)
Copy the vendor/ytake/laravel-smarty/src/config/ytake-laravel-smarty.php
file to your local config directory
config for Production
edit config/ytake-laravel-smarty.php
// enabled smarty template cache 'caching' => true, // default false // disabled smarty template compile 'force_compile' => false, // default true(for develop)
Or
add .env file
SMARTY_CACHE=true
SMARTY_COMPILE=false
edit config/ytake-laravel-smarty.php
'caching' => env('SMARTY_CACHING', false), 'force_compile' => env('SMARTY_FORCE_COMPILE', true),
and more..!
Basic
easily use all the methods of Smarty
// laravel5 view render view("template.name"); // Laravel blade template render(use Facades) \View::make('template', ['hello']); // use Smarty method \View::assign('word', 'hello'); \View::clearAllAssign(); // smarty method
View Composer, and View Share
$this->app['view']->composer('index', function (View $view) { $view->with('message', 'enable smarty'); }); $this->app['view']->share('title', 'laravel-smarty');
Hello Laravel.Smarty {$title} {$message}
Artisan
smarty's cache clear, remove compile class from Artisan(cli)
Template cache clear
$ php artisan ytake:smarty-clear-cache
Remove compile file
$ php artisan ytake:smarty-clear-compiled
Template Compiler
$ php artisan ytake:smarty-optimize
Template Caching
choose file, memcached, Redis
(default file cache driver)
// smarty cache driver "file", "memcached", "redis" 'cache_driver' => 'file', // memcached servers 'memcached' => [ [ 'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100 ], ], // redis configure 'redis' => [ [ 'host' => '127.0.0.1', 'port' => 6379, 'database' => 0, ], ],
example
registerFilter in ServiceProvider
registerFilter in Controller
layout.sample
layout.extends.sample