Template
Method Reference
title()
Set the title of the page.
Parameters
- $title1 - string REQUIRED - send as many parameters as you like, they will be imploded with $config['title_separator'] to create a single string, which can be called with $template['title']; in your layouts.
Usage
$this->template->title('Blog', $article->title);
set()
Set data using a chainable method. Provide two strings or an array of data.
Usage
$this->template->set('foo', $bar);
Usage
$this->template->build('welcome_message', array('message' => 'Hi there!'));
prepend_metadata()
Add a line to the start of the $template['metadata'] string.
Parameters
- $line - string REQUIRED - Metadata line.
Usage
$this->template->prepend_metadata('< script src="/js/jquery.js"></script>');
append_metadata()
Add a line to the end of the $template['metadata'] string.
Parameters
- $line - string REQUIRED - Metadata line.
Usage
$this->template->append_metadata('< script src="/js/jquery.flot.js"></script>');
set_layout()
All Layout files should be in the layout folder and by default will be application/views/layouts/default.php, but this can be changed.
Parameters
- $layout - string REQUIRED - name of the theme.
Usage
$this->template
->set_layout('two_col') // application/views/layouts/two_col.php ->build('welcome_message'); // views/welcome_message
set_theme()
Will override the theme set in $config['theme'].
Parameters
- $theme - string REQUIRED - name of the theme.
set_partial()
Set Partials from view files.
Parameters
- $name - string REQUIRED - assign a name to the partial.
- $view - string REQUIRED - name of the view file to look for.
- $data - array/object OPTIONAL - assign some extra data JUST for this partial.
Usage
$this->template // application/views/some_folder/header ->set_partial('header', 'some_folder/header') // application/views/layouts/two_col.php ->set_layout('two_col') // views/welcome_message ->build('welcome_message');
inject_partial()
Inject a chunk of HTML as a Partial.
Parameters
- $name - string REQUIRED - assign a name to the partial.
- $string - string REQUIRED - Chunk of HTML/Text/Whatever to go into the partial.
- $data - array/object OPTIONAL - assign some extra data JUST for this partial.
Usage
$this->template // application/views/some_folder/header ->inject_partial('header', '<h1>Hello World!</h1>') // application/views/layouts/two_col.php ->set_layout('two_col') // views/welcome_message ->build('welcome_message');
load_view()
Load views from theme paths if they exist.
Parameters
- $view- string REQUIRED - Name of the view to be loaded.
- $data - array/object OPTIONAL - assign some extra data for this view.
Return
- string. The contents of the rendered view.
build()
Build the entire HTML combining partials, layouts and views.
Parameters
- $view - string REQUIRED - Name of the view to use for the template body.
- $data - array/object OPTIONAL - Add more data to be mixed with any data already added via $this->template->set();.
Return
- string. If the 3rd argument is set to TRUE this method will return the HTML as a string.