The examples on the previous page use a mixture of tables and direct printing. Normally, the table commands such as pTable, tRow and endTable output the HTML they generate directly via the PHP print command so this is no problem. However, the library also provides an alternative method of HTML page creation which lends itself better to templates. This is a class called HtmlPage.
An HtmlPage object can "plug" items into the template either into named locations or into the general "content" area. Here is an example:
The above example is doing the following:
- A template is defined as $tpl.
- An HtmlPage object is initialised as $hpg.
- The template is added to $hpg.
- Named parts of the template are filled in. There are two methods of doing this: the first, using the replace method, will substitute the entire section with the supplied data; the second, using the add method, will add the supplied data to anything previously added to that section. The add method either adds to the named section or to the default "CONTENT" section if only the data is supplied. The addPara method is a specialised version of add which wraps <p> tags around the supplied data.
- Finally, the page is sent to the browser via the output method.
The use of common templates with HtmlPage mean that all pages on a site that use the same template can be updated at once by altering the template.
[MORE COMING SOON(ish)]