smarty template engine for laravel
##Basic
laravel4でsmartyを使用できます。
bladeの構文をそのまま使用することができ、
それに加え、View Facadeを通じてsmartyのmethodはすべて利用可能です。
easily use all the methods of smarty
// laravel blade template render
\View::make('template', ['hello']);
// use smarty method
\View::assign('word', 'hello');
\View::clearAllAssign(); // smarty method
###example
registerFilter in ServiceProvider
registerFilter in Controller
layout.sample
layout.extends.sample
##Install
###for Laravel4.2.*
"require": {
"ytake/laravel-smarty": "1.2.*"
},
###for Laravel4.1.*
"require": {
"ytake/laravel-smarty": "1.1.*"
},
###for Laravel5(develop)
"require": {
"ytake/laravel-smarty": "dev-develop-5"
},
##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を追加してください。
add providers
'providers' => [
'Ytake\LaravelSmarty\SmartyServiceProvider'
]
configファイルをpublishします。
publish configure
$ php artisan config:publish ytake/laravel-smarty
app/config/packages配下に追加されます。
publish to app/config/packages
views配下にsmartyファイルがあればそれをテンプレートと使用し、
なければ通常通りbladeテンプレートかphpファイルを使用します。
smartyテンプレート内にも*{{app_path()}}*等のヘルパーそのまま使用できます。
その場合、delimiterをbladeと同じものを指定しない様にしてください。