Using Code Igniter's Hooks feature to create a template engine. (CI 3.x)
Steps:
Enable system hooks on your application/config/config.php file.
$config['enable_hooks'] = TRUE;
Define a hook including the following code snippet to your application/config/hooks.php file:
$hook['display_override'] = array(
'class' => 'HulkTemplate',
'function' => 'exec',
'filename' => 'HulkTemplate.php',
'filepath' => 'hooks'
);
Upload the provided files to your project:
- application/hooks/HulkTemplate.php
- application/views/template.php
-
Customize your template in application/views/template.php file
-
Customize specific title and content for each page in its controller, see below:
$this->title = 'About Us';
$this->load->view('aboutus');
The title and content will be inserted into your template file before the page is displayed to the user.