Saturday 30 June 2012

Cakephp Layout - How to set Layout


A layout contains presentation code that wraps around a view. Anything you want to see in all of your views should be placed in a layout.
Layout files should be placed in /app/views/layouts. CakePHP's default layout can be overridden by creating a new default layout at /app/views/layouts/default.ctp. Once a new default layout has been created, controller-rendered view code is placed inside of the default layout when the page is rendered.
When you create a layout, you need to tell CakePHP where to place the code for your views. To do so, make sure your layout includes a place for $content_for_layout (and optionally, $title_for_layout).





Example is below

<html>
<head>
<!-- Include external files and scripts here (See HTML helper for more info.) -->
<?php echo $scripts_for_layout ?>
<title>
<?php echo $title_for_layout ?>
</title>
</head>
<body>
<?php echo $content_for_layout ?>
</body>
</html>