-
Notifications
You must be signed in to change notification settings - Fork 26
codeigniter template
[h3] Overview [/h3] This tutorial is based on Phil Sturgeon's template and themeing library which can be found at:
[url]http://bitbucket.org/philsturgeon/codeigniter-template/[/url]
[h3]Installation[/h3] After downloading the codeigniter-template package from BitBucket, unpack it to the correct library and config directory locations.
[h3] Example1: Basic Templating [/h3]
-
Open up application/config/autoload.php and add 'template' to the libraries array htat are being autoloaded. For example: [code] $autoload['libraries'] = array('database', 'template'); [/code]
-
Create the directory applications/views/base/ and add a layout.php file including a basic html layout such as: [code]
<html > <head> <?php echo $template['partials']['header']; ?> </head> <body> <?php echo $template['body']; ?> </body> </html> [/code]
-
Create the directory applications/views/basic/partials and add a header.php file in there including your css and metadata stuff, for example: [code] <title><?php echo $template['title'];?> | Example Site </title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> [/code]
-
Now in some global code (this could be a post_controller_constructor Hook or [url=/wiki/MY_Controller_-_how_to_extend_the_CI_Controller/]MY_Controller[/url]) add to the constructor the template configuration, for example: [code] function __construct() { parent::Controller();
$this->template->set_layout('layout'); $this->template->enable_parser(FALSE); // default true $this->template->set_partial('header', 'partials/header', FALSE);
} [/code]
-
in your controller, if you are using MY_Controller you should extend MY_Controller not Controller. For the index function you should use this code to display your view: [code] $this->template->build('body', $data); [/code] where index is the view file application/views/index.php or if you are currently using a modular system like Modular Separation it will look in application/modules/modulename/views/index.php.
-
the reference to the 'body' in the build() method above represents the view called body.php inside the module's views/ directory and so you should create it and add some content there
[h4] Contact [/h4] Liran Tal [email protected] For any updates, improvements and bugs