3.9.4 Themes
You can take advantage of themes, making it easy to switch the look and feel of your page quickly and easily.
To use themes, you need to tell your controller to use the ThemeView class instead of the default View class.
class ExampleController extends AppController {
var $view = 'Theme';
}
class ExampleController extends AppController {var $view = 'Theme';}
To declare which theme to use by default, specify the theme name in your controller.
var $theme = 'example';
var $theme = 'example';
You can also set or change the theme name within an action or within the beforeFilter or beforeRender callback functions.
$this->theme = 'another_example';
$this->theme = 'another_example';
Theme view files need to be within the /app/views/themed/ folder. Within the themed folder, create a folder using the same name as your theme name. Beyond that, the folder structure within the /app/views/themed/example/ folder is exactly the same as /app/views/.
For example, the view file for an edit action of a Posts controller would reside at /app/views/themed/example/posts/edit.ctp. Layout files would reside in /app/views/themed/example/layouts/.
If a view file can't be found in the theme, CakePHP will try to locate the view file in the /app/views/ folder. This way, you can create master view files and simply override them on a case-by-case basis within your theme folder.
If you have CSS or JavaScript files that are specific to your theme, you can store them in a themed folder within webroot. For example, your stylesheets would be stored in /app/webroot/themed/example/css/ and your JavaScript files would be stored in /app/webroot/themed/example/js/.
All of CakePHP's built-in helpers are aware of themes and will create the correct paths automatically. Like view files, if a file isn't in the theme folder, it'll default to the main webroot folder.
