In Laravel 4, my controller uses a Blade layout:
class PagesController extends BaseController {
protected $layout = 'layouts.master';
}
The master layout has outputs the variable title and then displays a view:
...
<title>{{ $title }}</title>
...
@yield('content')
....
However, in my controller I only appear to be able to pass variables to the subview, not the layout. For example, an action could be:
public function index()
{
$this->layout->content = View::make('pages/index', array('title' => 'Home page'));
}
This will only pass the $title
variable to the content section of the view. How can I provide that variable to the whole view, or at the very least the master layout?
If you're using @extends
in your content layout you can use this:
@extends('master', ['title' => $title])