I googled two hours, but not found answer. Maybe you can help.
When I define in MyController:
class MyController extends Base_Cont
To use layouts in controllers, you must specify:
public $layout = 'layouts.default';
You can also not return in the method as it will override the use of $layout. Instead, to embed your content within the layout you use:
$this->layout->nest('content', 'entries.index', array('entries' => $entries));
No need to return anything in your method now. This will fix it.
Edit:
"Beautiful Ways?"
$this->layout->nest('content', 'entries.index')->with('entries', $entries);
$this->layout->content = View::make('entries.index')->with('entries', $entries);
$this->layout->entries = $entries;
$this->layout->nest('content', 'entries.index');
It should be
public $layout = 'layouts.default';
Here's the link Templating - The Basics
Now you can return your layout like this
$view = View::make('entries.index')->with('entries', $entries);
$this->layout->content = $view->render();
class BaseController extends Controller {
/**
* Setup the layout used by the controller.
*
* @return void
*/
/*Set a layout properties here, so you can globally
call it in all of your Controllers*/
protected $layout = 'layouts.default';
protected function setupLayout()
{
if ( ! is_null($this->layout))
{
$this->layout = View::make($this->layout);
}
}
}
class HomeController extends BaseController {
public function showHome()
{
/*now you can control your Layout it here */
$this->layout->title= "Hi I am a title"; //add a dynamic title
$this->layout->content = View::make('home');
}
}
Ref: http://teknosains.com/i/tutorial-dynamic-layout-in-laravel-4