Working with Multiple Template Files to Separate Logic from Presentation - Setting up the basics of chunked caching: defining multiple template files (
Page 2 of 4 )
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"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>{title}</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-
8859-1" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<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>
</body>
</html>
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.
| | Discuss Working with Multiple Template Files to Separate Logic from Presentation | | | | | | | Over the course of this article, you'll learn how to build a powerful template... | | | | | | Hi, first of all great article.
I am having trouble with this line:
// clean up... | | | | | | Hey, thank you for the kind comments on this article. Regarding your question, try... | | | | | | USE SMARTY (template engine) and you will bew happy!
LOOK... | | | | | | Thank you for your feedback regarding this article. I agree with you that Smarty is... | | | | | | Parse error: parse error, unexpected '{' in... | | | | | | Thank you for your comments on this article. Regarding your question, I used the... | | | | | | My server is running php 4 and PHP 5, i had to name the file... | | | | | | I'm glad to know you fixed out the problem.
Thank you again for the kind words on... | | | | | | Awesome tutorial ... I've found this series not only a great primer for learning how... | | | | | | Thank you for your kind words on my PHP article. I really appreciate your comments.... | | | | | | First of all thanks for you usefull template engine.
Second: I'm not a skilled PHP... | | | | | | Thank you for commenting on my PHP article. Now, you can have a readable version of... | | | | | | Thank you very much for your prompt answer.
I also found it by myself 5 minutes... | | | | | | You're welcome Massi. I'm glad to know the problem was solved... | | | | | | Hello Alejandro,
thanks for the good tutorial, I have this code on... | | | | | | Hi Roy,
Thank you again for the comments on my PHP article. Concerning your... | | | | | | Alejandro, your tutorials are very insightful and very easy to follow. I am one of... | | | | | | Hey Jules,
Thanks for the kind words on my PHP articles. In fact, compressing the... | | | | | | I see that this is the third article in the series "seperating logic...", but i cant... | | | | | | Here you have the links to the previous... | | | | | | Hi Alejandro:
I downloaded the files for this tutorial and I get an error-like... | | | | | | I also get this error-like "Array to string conversion" notice when trying the... | | | | | | Hi once more Alejandro:
I forgot to show the affected line. Its the... | | | | | | Hello,
You’re getting the parser’s notice due to the new error reporting... | | | | | | >>> Post your comment now! | | | | | |
|
 |