You are Here: POOF > Manual > Inverted Nested Template Processor POOF Version 0.4.1
POOFManualDownloadsLinks
POOF | Modules | Examples | Inverted Nested Template Processor | PHPDocs
Inverted Nested Template Processor

Inverted Nested Template Processor

Before describing an Inverted Nested Template Processor I will briefly explain Templates and Nested Templates and the advantages and discrepancies of each.

Template

A Template in PHP is a method of separating the application code from the layout. A description and some advantages to using a Template are focused on at http://phpbuilder.com/columns/kendall20001122.php3

Templates improve on using include(‘header.php’) and include(‘footer.php’) because the template html is in one file and more than one template variable, such as the page title and page content, can (easily) be filled. However, with a single layer of templates, there will be much duplication of html in the website since template can be used only to give the general look of the page. Further refinements require another template to be created.

Nested Template

A nested template occurs when a template variable holds another template. Nested Templates allow the developer to define a general site template and then add to it by inserting other templates into a general site template variable. This allows the developer to add to a template without having to rewrite the template that is being added to. This makes the site much more maintainable since the templates will, hopefully, have no duplications.

Consider Template 1 and Template 2.

Template 1:

<html>
<head>
</head>
<body>
<?php echo $Content ?>
</body>
</html>

Template 2:

<table>
<tr>
<td><h1>Here is some content</h1></td>
</tr>
<tr>
<td><?php echo $Content ?></td>
</tr>
</table>

First, start with Template 1. Insert Template 2 into the $Content variable inside Template 1. Then insert Some Text into $Content in Template 2.

Figure 1 – The Nested Template

With nested templates, the parent templates have to be defined first. In a website, every page using a template will need all of the parent templates defined and nested before the leaf template can be inserted. This means each page has to know all of its parent templates. This makes the site hard to maintain because moving a directory or a page requires the parent templates for all the pages in the moved directory and its subdirectories to be changed.

Inverted Nested Template

An Inverted Nested Template is a template that is completed using a bottom-up approach, rather than a top-down approach that a Nested Template takes. This means the child template only has to know its immediate parent template, rather than all its parent templates. If the directory is moved, and there is a base template for that particular directory, only the directory base template needs to be changed to account for its new parent.

Consider Template 1 and 2 again.

           

Figure 2 – The Inverted Nested Template

Inverted Nested Templates will save development and maintenance time from all the presented methods.

SourceForge Logo