Reputation: 47321
I have something like this :
class AController extends BaseController
{
protected $layout = "templates.layouts.master";
protected $data = "something";
public function alt()
{
// this is wrong
// i want to override "templates.layouts.master"
// missing something obviously here
$this->layout = ??? what should do?
$this->layout->content = View::make("content", $this->data);
}
}
In method alt, I wish to use different layout than the default "templates.layouts.master".
I have very limited laravel 4 knowledge. This maybe something easy to achieve, but is beyond my knowledge.
Possible solutions that I forsee:
Which is the correct way?
Upvotes: 3
Views: 3067
Reputation: 12293
You can set the layout to be another view per method:
class AController extends BaseController
{
protected $layout = "templates.layouts.master";
protected $data = "something";
public function alt()
{
$this->layout = View::make('templates.layouts.alt');
$this->layout->content = View::make("content", $this->data);
}
}
If you check out the BaseController
, you'll see that all it does is call View::make() to set the layout view. You can do the same to over-ride its default.
Upvotes: 8
Reputation: 47321
OK, solution 1 seems to be possible, but I think is fugly :
class AController extends BaseController
{
public function __construct()
{
if (Request::is("..."))
{
$this->layout = "alternative layout";
}
}
}
Upvotes: 1