Skip to content

codeigniter template

World Wide Web Server edited this page Jul 4, 2012 · 12 revisions

Category:Library::Community

[h1] Overview [/h1] This tutorial is based on Phil Sturgeon's template and themeing library which can be found at: http://github.com/philsturgeon/codeigniter-template

[h1] Installation [/h2] After downloading the codeigniter-template package from github, unpack it to the correct library/helper/config directory locations.

[h1] Example1: Basic Templating [/h1]

[li]

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

<html > <head> echo $template['partials']['header']; </head> <body> <?php $this->load->view('base/') ?> <?php echo $template['body']; ?> </body> </html> [/code] [/li]

[li] 2. 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> Example Site </title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> [/code] [/li]

[li] 3. in MY_Controller add to the constructor the template configuration, for example: [code] function __construct() { parent::Controller();

    $this->template->set_layout('base/layout');
    $this->template->enable_parser(FALSE); // default true
    
    $this->template->set_partial('header', 'base/partials/header', FALSE);
    
}

[/code] [/li]

[li] 4. in your controller, whatever it may be, you should extend MY_Controller obviously and for the index function you should use: [code] $this->template->build('base/index', $data); [/code] where base/index is the view file in the module's views/base/ directory [/li]

Clone this wiki locally