Template Library

Derek Jones edited this page Jul 5, 2012 · 7 revisions
Clone this wiki locally

Category:Library::Community | Category:Library::Template Engine The idea of this library is to make all of those display related chunks of code much easier to manage. No more painstaking breadcrumb creation, multiple lines of view segment compilation or annoying sub-page navigation. Now you can get all you milarkery done in one place.

This template lib was originally designed for plain old CodeIgnitor, but now it is been modified to work with Zack's Modular Seperation. Im sure with a few small changes (perhaps with none, who knows?!) it can work fine without modules.


// Simple useage
$this->template->title('Something');
$this->template->create('viewname', $data);

// HTML Mode
$this->template->html_mode(true);
$this->template->create('<p>Hello World</p>');

// Wrap Mode Off - ignores the layout file and just calls the view you select.
$this->template->wrap_mode(false);
$this->template->create('pagename', $data);

// Automatic Title Creation
// Uses module name (failing that as most dont use it, class name) then method name using Humanize()
// Eg: blogs/my_blog would give you "Blogs > My Blog"
$this->template->create('something', $data);

// Breadcrumbs
// Automatically includes the module name (you should change this to class name)
$this->template->crumb('My Blog', 'blogs/my_blog');
$this->template->crumb('This Blog Entry');
$this->template->create('something', $data);

// Extra head
$this->template->extra_head('&lt;meta name="keywords" content="bla, bla, bla " /&gt;');

// Extra Head combines well with my asset helper
// http://codeigniter.com/wiki/Asset_Helper/
$this->template->extra_head( css_asset('blog.css') );

Download this Library! - File:Template_Lib.zip

Here is an example layout.php file to get you started. Put this in your main views folder and modify away!

Dont forget to also download or create a basic libraries/Defaults.php. This allows you to throw in as much code as you want, and it will be loaded on ALL pages and passed to the template (not accessable in controllers, models or libs, only views).