dsolivier
dsolivier

Reputation: 55

CakePhp 2.x: having custom layout only for index page

I'd like to have a custom layout for the indexpage only, the rest of the pages can use the default.ctp.

I've read on different forums and blogs on how to do this, but I can't quite figure it out.

What I have so far in the app/Config/routes.php:

Router::connect('/', array('controller' => 'newsposts', 'action' => 'start', 'home'));

This works fine, but results in the default.ctp being used. I've already added a home.ctp in the app/View/Layouts folder.

Now, how do I make use of the home.ctp instead of the defautl.ctp only on the homepage? I've read something about adding some lines in the beforeFilter() in app/Controller/AppController.php but I have no clue on how to do this...

Upvotes: 0

Views: 168

Answers (1)

Salines
Salines

Reputation: 5767

Use:

public function start()
{
    $this->layout = 'home';
}

Upvotes: 2

Related Questions