A weblog about coding, interface design, productivity and the art of making people love the web.

Templates in CodeIgniter

One of the most annoying stuff for CodeIgniter developers is having to include a header/footer/etc part in each and every view. CodeIgniter out of the box does not include template support (in the sence of a Joomla template or Wordpress theme). I have created a small library to assist you in using "templates" in CodeIgniter.


How to use

1) First copy the file MY_loader.php to your application/libraries folder.

2) Check the example folder to see how a template should look like.

3) Simply do:

$this->load->template('template_name', $data); 
$this->load->view('view_name', $data);


The template loading is done in pretty much the same way as the views loading. However please read the comments inside the MY_loader.php file. It takes one minute and you'll get the whole picture about how you can pass $data arrays containing variables.

I hope you liked this article. I'd love to hear your opinion on twitter.

Saturday, July 18, 2009, 07:00. Tagged: downloads code codeigniter