Documentation


Template

Method Reference

 

title()

Set the title of the page.

Parameters

  1. $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

  1. $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

  1. $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

  1. $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

  1. $theme - string REQUIRED - name of the theme.
 

set_partial()

Set Partials from view files.

Parameters

  1. $name - string REQUIRED - assign a name to the partial.
  2. $view - string REQUIRED - name of the view file to look for.
  3. $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

  1. $name - string REQUIRED - assign a name to the partial.
  2. $string - string REQUIRED - Chunk of HTML/Text/Whatever to go into the partial.
  3. $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

  1. $view- string REQUIRED - Name of the view to be loaded.
  2. $data - array/object OPTIONAL - assign some extra data for this view.

Return

build()

Build the entire HTML combining partials, layouts and views.

Parameters

  1. $view - string REQUIRED - Name of the view to use for the template body.
  2. $data - array/object OPTIONAL - Add more data to be mixed with any data already added via $this->template->set();.

Return