Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Template library for CodeIgniter which supports modules, themes, partial views, etc.
PHP JavaScript
Tag: v1.5

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.



CodeIgniter-Template is a Template library that helps your build complex views with CodeIgniter. It has logic to work with themes & modules and helps add your title, meta-data, breadcrumbs and partial views.


  1. PHP 5.1+
  2. CodeIgniter 1.6.x - 2.0-dev


For any of this to work well, you need some global code running. You can do this by creating a hook or use MY_Controller. I take MY_Controller one step further and have Public_Controller and Admin_Controller, from which all of my controllers inherit shared logic for the frontend or the backend.

Global methods

Wrap application/views/layout_name.php around your view


Use Parser for the layout and loaded views

$this->template->enable_parser(FALSE); // default = TRUE

Set a theme name and your layout will be loaded from application/themes/theme_name/views/layouts/layout_name.php


Per-page methods

Load and output view (from the current module, or from the view folder if you aren't using a module

$this->template->build('view_name', $data);

Return the built template

$output = $this->template->build('view_name', $data, TRUE);

Set layout and build template

$this->template->set_layout('layout_name'); // Should be in application/views/layout_name.php
$this->template->build('view_name', $data);

Set page title manually. The default is "Module | Controller | Method".

$this->template->title('Some title')->build('view_name', $data);

Set partial view (assigns a view to $template['partials']['partial_name']). It will use the same logic to find a view partial as build(), in that it will try and find it in modules and themes or just use global view folder.

$this->template->set_partial('sidebar', 'partials/sidebar_view');

// Send extra data to a partial
$this->template->set_partial('partial_name', 'partials/view_file', array('foo' => 'bar');

Set breadcrumbs

$this->template->set_breadcrumb('Blog', 'blog/index')
    ->set_breadcrumb($article->category->title, 'blog/category/'.$article->category->id)
    ->set_breadcrumb($article->title, 'blog/article/'.$article->id);

Add lines of metadata

// <meta name="keywords" content="some, keywords, somebody, for, to, comma-separate" />
$this->template->set_metadata('keywords', 'some keywords somebody for to comma-separate');

// <link rel="canonical" href="" />
$this->layout->set_metadata('canonical', site_url('some/other/page'), 'link');

Pretty much all of the methods support method-chaining in PHP 5 to make syntax shorter.


Drop the libraries/Template.php file into your applicaiton/libraries folder.

Something went wrong with that request. Please try again.