I don't know if this will help you, but this was how I did my template system for the longest time before moving on to a more advanced method.
Top Head: views/inc/top_head.php
<html>
<head>
<!-- all of your imports you want across all pages -->
Bottom Head: views/inc/bottom_head.php
I do it this way so that I can split and add custom Javascript things and maybe bring in special case imports.
</head>
<body>
<div id="main_container">
<div id="navigation">
<?php
// DO YOUR NAVIGATION MAGIC HERE
if($is_logged_in) :
// BAM MAGIC DONE
else :
// No magic show here
endif;
?>
</div>
Footer: views/inc/footer.php
This is where you will put in your footer things etc....
</div>
</body>
Now we are at the point that we need to actually fill content in to the template
Index Page: /views/some_controller/index.php
<?php $this->load->view('inc/top_head.php'); ?>
<?php $this->load->view('inc/bottom_head.php;) ?>
<h1>Hello</h1>
<p>Some filler content and stuff I guess would go here...Of course</p>
<?php $this->load->view('inc/footer.php'); ?>
So there, we have a quick template system. Now to show you what I have done for a controller
<?php
class Some_Controller extends Controller {
public $page_data;
public function __construct() {
parent::__construct(); // Load parent constructor
// This is page data that we obviously don't want to keep retyping
$this->page_data = array(
'is_logged_in' => FALSE, // Obviously do some test here
'page_title' => 'Some Title'
);
}
public function index() {
$this->_load('some_controller/index');
}
/** Should think of a better name but meh */
private function _load($view) {
$this->load->view($view, $this->page_data);
}
}
I hope this helped in some way or another. Mind you this is a quick write up. If I really wanted this to go into production, I would have moved the _load
function into a parent class and extended it. I would also probably move the page_data
variable along with it.