Part of the EllisLab Network
x
 
Create New Page
 View Previous Changes    ( Last updated by liri )

codeigniter-template

Category:Library -> Community

Overview

This tutorial is based on Phil Sturgeon’s template and themeing library which can be found at:

http://bitbucket.org/philsturgeon/codeigniter-template/

Installation


After downloading the codeigniter-template package from BitBucket, unpack it to the correct library and config directory locations.

Example1: Basic Templating


0. Open up application/config/autoload.php and add ‘template’ to the libraries array htat are being autoloaded. For example:

$autoload['libraries'= array('database''template'); 

1. Create the directory applications/views/base/ and add a layout.php file
including a basic html layout such as:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html >
<
head>
        
<?php echo $template['partials']['header']?>
</head>
    <
body>
        
<?php echo $template['body']?>
    
</body>
</
html

 

2. Create the directory applications/views/basic/partials and add a header.php file
in there including your css and metadata stuff, for example:

<title><?php echo $template['title'];?> Example Site </title>
<
meta http-equiv="content-type" content="text/html; charset=utf-8" /> 

 


3. Now in some global code (this could be a post_controller_constructor Hook or MY_Controller) add to the constructor the template configuration, for example:

function __construct()
    
{
        parent
::Controller();
    
        
$this->template->set_layout('layout');
        
$this->template->enable_parser(FALSE); // default true
        
        
$this->template->set_partial('header''partials/header'FALSE);
        
    

 

 

4. 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:

$this->template->build('body'$data); 

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.


5. 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

 

Contact

Liran Tal <liran.tal@gmail.com>
For any updates, improvements and bugs

Categories: