default.thtml
To create your own layout, create the following default.thtml layout and put it in /app/views/layouts/
A sample /app/views/layouts/default.thtml, defining $title_for_layout and $content_for_layout, are all you need to display a page.
<html>
<head>
<title> MySite : <?php echo $title_for_layout;?></title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<?php echo $html->charset('UTF-8')?>
<?php echo $html->css('default')?><!-- //in /app/webroot/css/ -->
</head>
<body>
<?php echo $html->image('my_logo.png',array('alt'=>'MySite'))?>
<div class="content">
<?php echo $content_for_layout;?>
</div>
</body>
</html>
Per-page CSS/Javascript
To add javascript/css to your page (but only on certain pages) and also use a layout template, handle all the cases in your template and specify which cases to use in your controller.
Continuing with the above example...
<html>
<head>
<title> MySite : <?php echo $title_for_layout;?></title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<?php echo $html->charset('UTF-8')?>
<?php echo $html->css('default')?><!--//this guy will be included on every page -->
<?php if(isset($myjavascriptfile)){ echo $javascript->link($myjavascriptfile); } ?> <!--//this guy will only be included if set in the controller -->
</head>
<body>
<?php echo $html->image('my_logo.png',array('alt'=>'MySite'))?>
<div class="content">
<?php echo $content_for_layout;?>
</div>
</body>
</html>
Then, in your controller code file, specify your cases ...
$this->set('myjavascriptfile','javascriptfile.js');
It would be trivial to convert the “set” variable to an array and just loop through the array in the template, including variables, as necessary.
ajax.thtml
Perhaps you need an empty layout for AJAX, this template (included with CakePHP) will display just your content.
<?php echo $content_for_layout?>