I'm new to working with CI and I have a question. More like a design method suggestion. I want to create a base template for static pages. Basically I want to load doc type, head, and the body but nothing else. I want the content to be loaded by whatever class/function I call via the URL. I know I can do this with a HTML template and str_replace() but is there a better way or some fancy CI method I'm not familiar with?
Here is what I have so far and it works but it's not the best.
class Sandbox extends CI_Controller {
public function __construct() {
parent::__construct();
//echo "hello world?";
}
public function load($what){
if ($what == 'something'){
if (!file_exists('application/views/content/'.$what.'.php')){
// Whoops, we don't have a page for that!
show_404();
}
$data = array();
$this->load->view('templates/header', $data);
$this->load->view('content/'.$what, $data);
$this->load->view('templates/footer', $data);
}
else { // Default load
$data = array();
$data['message'] = 'Hello World';
//$this->load->view('templates/header', $data);
$this->load->view('content/sandbox', $data);
//$this->load->view('templates/footer', $data);
}
}
}
When I load the view method it seems to work but I had to add the doctype and head to the template. I would prefer to load those seperately so do not have to create multiple headers. What I am looking for is a way to specifically load parts of the page and whatever scripts/css that are required for that given page.
Thanks for any advice.