Template Library

The template library powers all out the output on the PyroCMS public and admin pages. The template is auto-loaded, so there is no need to load it in your controllers.

Method Reference

title($title1, [$title2, $title3, …])

Sets the title of the page. You can send as many title parameters as you'd like, although the first one is required. Your titles will be imploded with the title string separator.

$this->template->title('The Current Page');

build($view, [$data])

The build function is what builds the output for the browser in PyroCMS and is used in lieu of simply loading a view. It will take the theme data, layout, and build those elements automatically, so your view file only needs to contain the actual page content.

$this->template->build('form', $this->data);

set($varname, $varvalue)

Sets data that can be used in your views. You can provide two strings or an array.

Two strings of data:

$this->template->set('foo', $bar);

Array of data:

$this->template->set(array('foo' => $bar, 'foo2' => $bar2));

prepend_metadata($string)

Adds a string to the start of the auto-generated metadata output.

$this->template->prepend_metadata('<script src="/js/jquery.js"></script>');

append_metadata($string)

Adds a string to the end of the auto-generated metadata output.

$this->template->append_metadata('<script src="/js/jquery.flot.js"></script>');

set_layout($layout_name)

Allows you to set a layout from your your_theme/views/layouts folder.

// This will use your_theme/views/layouts/two_col.html
// as the page layout.
$this->template->set_layout('two_col');

Note: When using Public_Controller and Admin_Controller, the layout is already set. However, in some cases, you may prefer to override this function or use set a layout outside of the PyroCMS base controllers.

set_theme($theme_name)

Allows you to set a theme.

$this->template->set_theme('my_theme');

Note: As with set_layout, the theme is already set when extending either the Public_Controller and Admin_Controller.

enable_parser(bool)

This allows you to enable the PyroCMS Lex tag parser. When the tag parser is off, PyroCMS tags will not work in your views.

$this->template->enable_parser(true);

enable_minify(bool)

Enables/disables the minification of assets added via the template library.

$this->template->enable_minify(true);

get_theme_path()

Returns the path of the current theme.

Chaining

The template library methods are frequently chained in PyroCMS, so you may see the functions called like this:

$this->template
    ->title($this->module_details['name'], lang('keywords:add_title'))
    ->set('keyword', $keyword)
    ->build('admin/form', $this->data);