I’m developing a application with CakePHP, and I have two layouts: one for the home page, and another for the rest of the application. Except for some coding on the header, they’re almost exactly the same. Is there something I can do to keep DRY, without using if () statements all over the layout?
I’m developing a application with CakePHP, and I have two layouts: one for the
Share
I’d suggest using a ton of elements. This way, you can still keep all of the code in one place. For example, if this is your home page layout (boilerplate excluded):
And this is your interior layout (where you want to display everything except for the frontPageNotification stuff:
Now, if they’re almost exactly alike, I would probably just use a single layout and have a few if statements within the layout itself to determine what’s to be displayed. Also, you can choose which elements get displayed by looking at the $this->params array to figure out which controller and action is behind the page being loaded. Like:
Which is, admittedly, rather ugly. Just trying to present all the options I could think of 🙂
Good luck