BladeView
Laravel's Blade template engine in CakePHP 3., (*1)
Install
Composer:, (*2)
[
"require": {
"dowilcox/blade-view": "0.2.*"
}
]
In your bootstrap.php:, (*3)
Plugin::load('BladeView', ['bootstrap' => false]);
In your controller:, (*4)
public $viewClass = '\Dowilcox\BladeView\View\BladeView';
Now change all the template files in src/Template from .ctp to .blade.php, (*5)
Usage
See Laravel's documenation for Blade: http://laravel.com/docs/4.2/templates., (*6)
CakePHP view functions and helpers work a bit different., (*7)
Variables
Before:, (*8)
<?php echo h($variable); ?>
After:, (*9)
{{{ $variable }}}
View functions:
Before:, (*10)
<?php echo $this->fetch(); ?>
After:, (*11)
@fetch()
Helpers (if loaded in a controller):
Before:, (*12)
<?php echo $this->Html->css(); ?>
After:, (*13)
@html->css()
More Examples
{{-- src/Template/Common/view.blade.php --}}
@fetch('title')
@fetch('content')
{{-- src/Template/Posts/view.blade.php --}}
@extend('/Common/view')
@assign('title', $post)
@start('sidebar')
<li>
@html->link('edit', [
'action' => 'edit',
$post['Post']['id']
])
</li>
@end()
{{-- The remaining content will be available as the 'content' block --}}
{{-- In the parent view. --}}
{{{ $post['Post']['body'] }}}