How do I change the layout of my home page?

Changing only the home page layout in cakephp

  • If my whole site is using the default.ctp layout specified in apps/view/layouts/default.ctp, how do I change only the home page layout to use homepage.ctp and leave the rest of the site using default.ctp?

  • Answer:

    Copy the /cake/libs/controller/pages_controller.php into your /app/controller/ dir and do either of the following: Add a line towards the end of display() to switch the layout if 'home' is requested: if ($page == 'home') $this->layout = 'homepage'; Create a home() method (or named however you like) in which you set $this->layout and re-route the / route in /app/config/routes.php to use this new method. Edit: In summary, you need some custom method in which you'll set $this->layout = 'homepage', that's all. You can do this in any of your controllers at any point, reusing the PagesController is just the most convenient and conventional way to do it in Cake.

Bradley at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.