Documentation


Template

Partials

When you start creating multiple Layouts you will soon start to realize that while they are not all the same they will share lots of stuff. Often the header will be different but there could be two columns instead of one, etc.

Partials can go anywhere in your views folder (or themes and modules view folder) like application/views/header.php.

To attach a Partial (from a view file) to a Layout you will need to use the set_partial() method. Give the partial name, then enter it's path and optionally give it some special data that will only exist for that partial.

You can also inject strings into the template as partials using the inject_partial() method. This method is almost identical to set_partial() but the second argument is a HTML string and not a view file.

Example (PHP)

The easiest layout in the world is this:

<!DOCTYPE html>
<html>
	<head>
		<?php echo $template['partials']['header']; ?>
	</head>
	<body>
		<h1><?php echo $template['title']; ?></h1>
		<?php echo $template['body']; ?>
	</body>
</html>

Example (Parser)

Using the parser syntax you can do this instead:

<!DOCTYPE html>
<html>
	<head>
		{$template.partials.header}
	</head>
	<body>
		<h1>{$template.title}</h1>
		{$template.body}
	</body>

</html>

NOTE: You can only use the Parser if you have also installed a Parser extensions like codeigniter-dwoo. This is because CI_Parser does not play nicely with arrays.