Home arrow PHP arrow Page 2 - Working with Multiple Template Files to Separate Logic from Presentation

Setting up the basics of chunked caching: defining multiple template files - PHP

Welcome to the last part of the series “Separating logic from presentation.” In three tutorials, this series teaches you how to develop an expandable template processor class using PHP 5, which exposes some useful features, such as recursive placeholder replacement, MySQL result sets processing, and parsing of dynamic PHP files, among others.

  1. Working with Multiple Template Files to Separate Logic from Presentation
  2. Setting up the basics of chunked caching: defining multiple template files
  3. Parsing multiple template files: redefining the “TemplateProcessor” class
  4. Putting the “TemplateProcessor” class to work: setting up a concrete example
By: Alejandro Gervasio
Rating: starstarstarstarstar / 9
May 16, 2006

print this article



One of the most remarkable benefits of chunked caching systems rests on the ability to cache different sections of a web page, which can be treated as independent structures. This concept makes a lot of sense if you consider that most websites have different areas, such as headers and footers that don’t change very often, and evidently can take advantage of a caching mechanism.

In this case, keeping in mind the fundamentals of a chunked caching system, I’m going to define three different template files, each of them corresponding to one particular section of a web page: header, body and footer respectively. Then, after defining all the template files, I’ll modify the signature for some methods of the “TemplateProcessor” class, so it can handle the templates as independent files, and eventually assign distinct cache expiration times to each of them, when their contents are cached.

Here are the three basic template files that I plan to use in conjunction with the template processor class. First, the “header_template.htm” file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=iso-
8859-1" />
<link rel="stylesheet" type="text/css" href="style.css" />
<div id="header">{header}</div>

Next, you can see the definition of the “body_template.htm” file:

<div id="content">{maincontent{staticdata}{dynamicdata}}</div>

And finally, the signature of the “footer_template.htm” file:

<div id="footer">{footer}</div>

As you can see, I simply split a typical template file into three different areas, so they can be handled separately. Also, I kept their structure basic, thus you can easily understand how distinct template files will be parsed and then cached, in accordance with their time expiries.

Now that you know how each template file looks, it’s time to move on and start coding the improved “TemplateProcessor” class. To see how this will be done, please click on the link below.

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: