dowilcox / blade-view
Blade template engine for CakePHP3
Installs: 29
Dependents: 0
Suggesters: 0
Security: 0
Stars: 15
Watchers: 4
Forks: 6
Open Issues: 2
Type:cakephp-plugin
Requires
- cakephp/cakephp: 3.0.*-dev
- cakephp/plugin-installer: dev-master
- illuminate/view: 4.2.*
This package is not auto-updated.
Last update: 2022-02-01 12:40:03 UTC
README
Laravel's Blade template engine in CakePHP 3.
Install
Composer:
[ "require": { "dowilcox/blade-view": "0.2.*" } ]
In your bootstrap.php:
Plugin::load('BladeView', ['bootstrap' => false]);
In your controller:
public $viewClass = '\Dowilcox\BladeView\View\BladeView';
Now change all the template files in src/Template from .ctp to .blade.php
Usage
See Laravel's documenation for Blade: http://laravel.com/docs/4.2/templates.
CakePHP view functions and helpers work a bit different.
###Variables Before:
<?php echo h($variable); ?>
After:
{{{ $variable }}}
###View functions: Before:
<?php echo $this->fetch(); ?>
After:
@fetch()
###Helpers (if loaded in a controller): Before:
<?php echo $this->Html->css(); ?>
After:
@html->css()
More Examples
{{-- src/Template/Common/view.blade.php --}} <h1>@fetch('title')</h1> @fetch('content') <div class="actions"> <h3>Related actions</h3> <ul> @fetch('sidebar') </ul> </div>
{{-- 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'] }}}