There is a download called CodeIgniter Library that makes all this very easy. Once you learn how to implement it, coding becomes very easy. It also allows you to change each page or controller to have different templates (layouts).
Using the system I mentioned above you can do the following:
<?php
function index() {
$data['some_variable'] = 'some data';
$this->template->write_view('content', 'page/home', $data);
$this->template->render();
}
?>
Anywhere you can also change which template you wish to use:
<?php
$this->template->set_template('login');
?>
All these templates have names that are kept in a configuration file. You can have as many templates as you wish.
The template file itself would look something like this:
<html>
.... etc. all other html elements
<body>
header html goes here
<?=$content?>
footer html goes here
</body>
</html>
You can even set up sections to be able to write your content to. I don't usually do this because it is including a lot of views, but if you need full control like this you are still able to do so:
<?php
function index() {
$data['header'] = 'header info';
$data['content'] = 'content info';
$data['sidebar'] = 'sidebar info';
$data['footer'] = 'footer info';
$this->template->write_view('content', 'page/home', $data);
$this->template->write_view('header', 'modules/header');
$this->template->write_view('sidebar', 'modules/sidebar');
$this->template->write_view('footer', 'modules/footer');
$this->template->render();
}
?>
HTML template code:
<html>
.... etc. all other html elements
<body>
<div id="header">
<?=$header?>
</div>
<div id="content">
<div id="left">
<?=$content?>
</div>
<div id="sidebar">
<?=$sidebar?>
</div>
</div>
<div id="footer">
<?=$footer?>
</div>
</body>
</html>
This way you only have to worry about including one file in all your Controller Functions. If you are not using PHP 5 (you should switch) then instead of using <?=$content?>
you will want to use <?php echo $content; ?>
.