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.
8 Comments »
Leave a comment
-
Recent
- My Move to the OSX (the dark-side)
- Skype & Apache conflict
- Simple yet effective way to replicate/mirror a database (any database at that)
- MySQL .frm recovery
- cakePHP calls crashing Apache
- Reformatting the default CakePHP layout (default.ctp)
- Syntax highlighting CakePHP using Eclipse
- Intersecting Entities on CakePHP Models
- Integrating Flickr into my PHP web-app
- Installing CakePHP
- Accessing a POP3 mailbox using PHP
-
Links
-
Archives
- October 2009 (2)
- April 2009 (2)
- February 2008 (1)
- January 2008 (6)
-
Categories
-
RSS
Entries RSS
Comments RSS
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.
Thanks, I was wondering where that default template was kept, I was searching in the App Directory.
Thanks
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.
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.
thanks, cakephp documentation is really easy, but kind of superficial.
i dont know what to do on this
[...] links related Reformatting the default layout Setting up the page [...]
$cakeDebug is where you controller dump and mysql queries report come out when app/config/core.php debug level is 2 or 3.