Rio Bautista’s TechLog

Tech solutions worth remembering

Reformatting the default CakePHP layout (default.ctp)

So after working on my authentication and application security I thought it’s time to mess with the looks of my site.  To start off, I wanted to obviously change the title of my site and do some minor changes on the main layout.

When you want to change something a programmers first instinct is to look for the text you want to change by maybe doing a grep or a file-search.   And I did, however, the title appeared in a file called default.ctp that was outside my app folder.  And we wouldn’t want to mess with anything outside the app folder specially if it’s inside the cake folder.

After a few more reading, it turns out we need to create our own default.ctp inside our app folder e.g. app/views/layouts/default.ctp.  So what I did was to copy the default.ctp from the cake/libs/views/layout and customized it to my preference.  I realized, the application title, is kinda redundant (as how it was implemented) and I was hoping there’d be some configuration item that I could simply change to globally specify my application title but no.  I’d probably have to do that myself as part of the configuration class.

I’m currently looking for a summary of all the available variables I could put in the default.ctp (of course with some description and explanation as to how to effectively use them)  like I see there’s $title_for_layout, $scripts_for_layout, $content_for_layout,  $cakeDebug.  If I don’t find one, then I’d probably write one if I later find to be important.

January 15, 2008 - Posted by Rio | CakePHP, php | | 9 Comments

9 Comments »

  1. FYI… any variables you set in your controller with $this->set(‘varName’, ‘blah’) will be available in your view and layout templates as $varName.

    $title_for_layout is populated by setting $this->pageTitle from your controllers or view templates.

    $scripts_for_layout is populated by $html->css() and $js->link(). You can set those in your view templates. Check out the documentation to understand how to use those.

    $content_for_layout contains the rendered view template.

    I don’t know what $cakeDebug has, though… I’ve always wondered that myself.

    Comment by Joel Stein | January 15, 2008 | Reply

  2. Thanks, I was wondering where that default template was kept, I was searching in the App Directory.

    Thanks

    Comment by Simon | January 27, 2008 | Reply

  3. If you bake your project to start with then the default view template will be copied across to your app directory. Also you can use the cake debug to display a table of SQL requests if the application is in debug mode, Otherwise it will be empty.

    Comment by will | July 30, 2008 | Reply

  4. Thanks for the tip. I’m new to CakePHP and was going to edit the default.ctp layout in ‘cake/libs/views/’ before I read your tip.

    Comment by Luke | August 5, 2008 | Reply

  5. thanks, cakephp documentation is really easy, but kind of superficial.

    Comment by ignacio | January 20, 2009 | Reply

  6. i dont know what to do on this

    Comment by pat | March 4, 2009 | Reply

  7. [...] links related Reformatting the default layout Setting up the page [...]

    Pingback by How to create custom layout for your website in CakePHP « Myles Kadusale’s Blog | May 14, 2009 | Reply

  8. $cakeDebug is where you controller dump and mysql queries report come out when app/config/core.php debug level is 2 or 3.

    Comment by Laban Johnson | July 7, 2009 | Reply

  9. Thanks, this was incredibly helpful!

    Comment by Viceroy | November 20, 2009 | Reply


Leave a comment