Package Data | |
---|---|
Maintainer Username: | ytake |
Maintainer Contact: | yuuki.takezawa@comnect.jp.net (Yuuki Takezawa) |
Package Create Date: | 2014-09-18 |
Package Last Update: | 2024-03-04 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-30 15:14:08 |
Package Statistics | |
---|---|
Total Downloads: | 324,264 |
Monthly Downloads: | 4,344 |
Daily Downloads: | 97 |
Total Stars: | 84 |
Total Watchers: | 9 |
Total Forks: | 24 |
Total Open Issues: | 6 |
Smarty Template Engine for Laravel
(Support for Laravel5.x and Lumen)
Require this package with Composer
$ composer require ytake/laravel-smarty
or composer.json
"require": {
"ytake/laravel-smarty": "^2.2"
},
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,
]
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);
$ php artisan vendor:publish
publish to config directory
Of Course, Blade Template can also be used to Render Engine.
Copy the vendor/ytake/laravel-smarty/src/config/ytake-laravel-smarty.php
file to your local config directory
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..!
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
$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}
smarty's cache clear, remove compile class from Artisan(cli)
$ php artisan ytake:smarty-clear-cache
| Options | description | | ------------- | ------------- | | --file (-f) | specify file | | --time (-t) | clear all of the files that are specified duration time | | --cache_id (-cache) | specified cache_id groups |
$ php artisan ytake:smarty-clear-compiled
| Options | description | | ------------- | ------------- | | --file (-f) | specify file | | --compile_id (-compile) | specified compile_id |
$ php artisan ytake:smarty-optimize
| Options | description | | ------------- | ------------- | | --extension (-e) | specified smarty file extension(default: .tpl) | | --force | compiles template files found in views directory |
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,
],
],
registerFilter in ServiceProvider
registerFilter in Controller
layout.sample
layout.extends.sample