smarty template engine for laravel
##Basic
laravelでbladeに加え、smartyを使用することができます。
bladeの構文をそのまま使用することができ、
View Facadeを通じてsmartyのmethodすべてが利用可能です。
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
##Install ###for Laravel5
"require": {
"ytake/laravel-smarty": "2.*"
},
###example
registerFilter in ServiceProvider
registerFilter in Controller
layout.sample
layout.extends.sample
##Artisan
キャッシュクリア、コンパイルファイルの削除がコマンドラインから行えます。
smarty's cacheclear, remove compile class from Artisan(cli)
###cache clear
$ 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 |
###remove compile class
$ php artisan ytake:smarty-clear-compiled
Options | description |
---|---|
--file (-f) | specify file |
--compile_id (-compile) | specified compile_id |
###compile
$ 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)
テンプレートキャッシュドライバにファイルキャッシュ、memcached, Redisが選択できます
デフォルトは通常のファイルキャッシュになっています
// 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,
],
],
install後、 app/config配下のapp.phpのproviders配列に以下のnamespaceを追加してください。
'providers' => [
'Ytake\LaravelSmarty\SmartyServiceProvider'
]
$ php artisan vendo:publish
publish to config directory
views配下にsmartyファイルがあればそれをview templateとし、
なければ通常通りbladeテンプレートかphpファイルを使用します。
smartyテンプレート内にも*{{app_path()}}*等のヘルパーそのまま使用できます。
その場合、delimiterをbladeと同じものを指定しない様にしてください。