Templates in CodeIgniter

One of the most annoying stuff for CodeIgniter developers is 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.

Download

Download Templates for CodeIgniter 0.1

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.

Vangelis Vangelis is a web developer with a passion for everything that helps the web evolve to a better place. He believes the web should be a friendly and safe place, connecting people and information in a transparent way.

When he is not at the computer coding something he enjoys endless pointless walks with his mp3 player.

Reader's Comments

  1. Eleftherios Kosmas |

    Hmmm CodeIgniter is a really powerfull php framework… being used to work in a “theme/template” way i had a weird sense of repetition with Codeigniter which didn’t felt right at all! Thanks a lot! Well done Vangeli! Bravo File.

Leave a Reply