Documentation


Template

Layouts

Layouts in this library are very similar to layouts in Ruby on Rails and other frameworks. The basic idea is that most of your pages will share the same header, footer, wrapping navigation, etc and only the actual body of the page will change. Using this logic you can avoid repeating yourself and having lots of similar HTML.

All layouts exist in application/views/layouts/ and the default Layout file funnily enough will be application/views/layouts/default.php.

Of course for many websites and applications you won't want every page to look the same, so for that we have the set_layout() method. You simply provide the name of the layout in the layouts folder and your page will be wrapped with that layout instead.

Example (PHP)

The easiest layout in the world is this:

<!DOCTYPE html>
<html>
	<head>
		<title><?php echo $template['title']; ?></title>
		<?php echo $template['metadata']; ?>
	</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>
		<title>{$template.title}</title>
		{$template.metadata}
	</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.