Laravel Blade Templating Engine
The Laravel Blade Templating Engine#
- Separation of Concerns
- Simplified syntax for embedding logic in views
for laravel
to recognise a file as blade it needs to end with: *.blade.php
Adding Variables to Views#
In the controller:
public function index(){
return view('index')->with('name', 'Surfer190');
}
or with a magic method
:
public function index(){
$name = 'Surfer190';
return view('index')->withName($name);
}
In the View:
<p>{{ $name }}</p>
Sending Multiple Variables#
In the Controller:
$data = array('name => 'Surfer190',
'gitserver' => 'github.com');
return view('index')->with($data);
In the View:
Your User is {{ $name }} on {{ $gitserver }}
The above can get quite messy so it is suggested to use PHP Compact
Eg.
$name = 'Surfer190';
$gitserver = 'Github';
return view('index', compact('name', 'date'));
## Setting Default Values in View