-
Notifications
You must be signed in to change notification settings - Fork 29
Templates
Templates are a View and a Layout combined.
- View in the sense that it renders itself by returning it's output
- Layout in the sense of it incorporating boilerplate stuff (headers, footers, etc)
A simple Template might look like
<html>
<body>
<?php
echo $this->includeBlocks();
?>
</body>
</html>
The call to includeBlocks()
is the key. That call will iterate over all the
Blocks of content that have been populated by the Controller. Templates store
all their Blocks in a multi-demensional array. The main or default set of
content Blocks are stored in the top of the array.
If no name is used when creating the Template, then the system will load the
default Template. This is a special filename that must exist, named
default.inc
. This filename must exist in each of the output formats exist.
Because we are combining the idea of a web application and a web service, Templates support multiple output formats. The default output format served is html; however, you can also provide other formats of the same Template as needed. (See Context Switching)
Both Templates and Blocks are organized by output format. Under each output format directory, the filenames should match.
Panels are a solution to a Layout problem with Templates. When you have a Template that is representing a whole page or screen, you often have multiple places on the screen to put content. A Controller may need to populate not just a main content area, but also a sidebar or header, or whatever.
I've called these panels, but there's not a Panel class or anything like that. As a Template author, a Panel is just a special string name you come up with to declare some portion of the layout.
<html>
<body>
<div id="side">
<?php
echo $this->includeBlocks('side');
?>
</div>
<div id="main">
<?php
echo $this->includeBlocks();
?>
</div>
</body>
</html>
In this example, the author decided to have a Panel called, "side". The call
to includeBlocks('side')
iterates over all the Blocks that have been put into
$this->blocks['side']
.
A Controller would populate this template something like this:
<?php
class SomeController extends Controller
{
public function index(Template $template)
{
$template->blocks[] = new Block('some_main_content_file');
$template->blocks['side'][] = new Block('some_sidebar_content_file');
}
}