I'm using CodeIgniter for a project, and I would like to customize the stylesheets that each page calls. I have a universal header and footer, being called in the controller like this:
$this->load->view("templates/header");
$this->load->view({page-to-load});
$this->load->view("template/footer");
As you probably can guess, the structure of the page is separated into three parts: the doctype along with the all the tags up to body, the body content itself, and lastly, the footer information along with the closing body and html tags.
I would like to insert a css resource into the header from the body content, so that I can leave the header as a generic file and just customize it from the content that is loaded, similar to how WordPress does it. However, I haven't found anything that can tell me how to accomplish this.
So my question is how do I customize what is in the header from the code in the body file?
In your controller, you can pass a variable to the view, like so:
$data['stylesheet'] = 'CustomPageStylesheet.css';
$this->load->view("templates/header", $data);
$this->load->view({page-to-load});
$this->load->view("template/footer");
Then, in your header view, you will have access to a variable $stylesheet
which you can use to load a custom stylesheet for that particular controller.