[eluser]TomTom[/eluser]
joeizang sorry I can't help you with your second question, but I'll try to answer the first one.
I agree that documentation for this otherwise brilliant library is unfortunately not very helpful, at least for beginners like myself. This is how you use it:
Code:
// This goes in a controller's method
// Any data to prepend before metadata in the page's head
$this->template->prepend_metadata('some code');
// Any data to append after metadata in the page's head
$this->template->append_metadata('some other code');
// Set view partials which are repeated throughout pages
// (file paths are relative to application/views)
$this->template->set_partial('header', 'path/to/file1');
$this->template->set_partial('footer', 'path/to/file2');
// Inject some code in a view partial
$this->template->inject_partial('sidebar', '<p><a href="#">Some</a> code</p>');
// Set a theme folder (application/themes/themefolder)
$this->template->set_theme('themefolder');
// Set a layout name (application/themes/themefolder/views/layouts/layoutname.php).
// If a theme isn't set, defaults to application/views/layours/layoutname.php
$this->template->set_layout('layoutname');
// Set value of $template['title']
$this->template->title('Some title');
// Set a variable called $varname and pass a value to it
$this->template->set('varname', 'Value of the $varname variable');
// Load the layout file and pass variables and view partials to it.
// mainview.php is the actual content of that particular loaded page
$this->template->build('mainviewfile');
Now, you don't benefit much if you put all this code in every method. The best results are achieved if you create a MY_Controller which extends CI_Controller, and put some or all of this code in it. You can also put some or all of this code in a __construct method of your controller so that it is processed for every method in it. Basically, the only code mandatory to go in the method is the very last line. Try to experiment a bit until you get results best for you.
This is an example of layoutname.php whether it be in views/layouts/ or themes/themefolder/views/layouts:
Code:
// Load the 'header' partial defined in the controller
<?=$template['partials']['header'];?>
// Load the 'title' from controller
<h1><?php echo $template['title']; ?></h1>
// Load the mainviewfile.php which contains the actual page content
<?php echo $template['body']; ?>
// Load the 'sidebar' partial from controller
<?=$template['partials']['sidebar'];?>
// Load the 'footer' partial from controller
<?=$template['partials']['footer'];?>
If you set up your controllers right (and extend them properly), you can get web pages that load a Header, Page Title, Sidebar and Footer automatically, and only change the inner content, depending on which page (which controller method) is loaded. You can also override this in every specific method if needed, the same way you've set it all up.