• Entries (RSS)
  • Comments (RSS)

Template Library for CodeIgniter, Simple, Fast and Easy!

Posted by | Posted in How to, OpenSource, PHP, Resources, Reviews, Tips and Tricks, Tutorials | Posted on 07-May-2009

Tagged Under : , , , ,

If you have not noticed, I just got started on CodeIgniter. I was really disappointed today when I noticed the lack of a template system in CodeIngiter to skin my little application. They say

The Template Parser Class is not a full-blown template parsing solution. We’ve kept it very lean on purpose in order to maintain maximum performance.

Lucky for me, I got a little help here, the library is great and works well for the latest version of CI too best of all its small and does not modify the CI code in anyway. It just uses the already available code to skin the application. Sleak!

I made a couple of modifications in the original library, here are my modifications

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Template {
	var $template_data = array();

	function set($name, $value) {
		$this->template_data[$name] = $value;
	}

	function load($template = '', $view = '' , $view_data = array(), $return = FALSE) {
		$this->CI =& get_instance();
		$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
		return $this->CI->load->view($template, $this->template_data, $return);
	}

	// load a default template 'template.php'
	function view($view = '' , $view_data = array(), $return = FALSE) {
		$this->CI =& get_instance();
		$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
		return $this->CI->load->view('template', $this->template_data, $return);
	}
}

/* End of file Template.php */
/* Location: ./system/application/libraries/Template.php */

So now I use it like

$this->template->view('my_view', $view_data);

instead of

$this->template->load('template', 'my_view', $view_data);

Hope it helps somebody.

Share This:
  • Facebook
  • Digg
  • Google Bookmarks
  • Sphinn
  • del.icio.us
  • Fark
  • LinkedIn
  • Live
  • MySpace
  • StumbleUpon
  • Technorati
  • Yahoo! Buzz
  • RSS

Related Posts (auto suggestions based on tags)

Post a Comment

Get Adobe Flash playerPlugin by wpburn.com wordpress themes