Skip to content

Templates

inghamn edited this page Sep 19, 2012 · 2 revisions

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.

Panels

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');
    }
}

Assets (css, javascript, etc.)

Partials

Helpers

Clone this wiki locally