Working with Multiple Template Files to Separate Logic from Presentation (
Page 1 of 4 ) 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.
A downloadable file for this article is available here.
Introduction
As you’ll hopefully recall, in the previous article I set up an illustrative hands-on example, aimed at demonstrating the functionality of the “TemplateProcessor” class that I wrote at the beginning of the series. With reference to this example, I created some basic dynamic PHP files, aside from fetching a small MySQL result set, and finally integrated all these data sources within an array of input tags, in order to show how the template processor class was capable of parsing a given template file.
Although the sample PHP files that I included as elements of the respective array of input tags were rather basic, they allowed me to illustrate the way that the “TemplateProcessor” class replaces the placeholders in question with data coming from different data sources. As I said repeatedly over the previous tutorials, the structure of this class is very expandable, thus if you need even more template processing features, in accordance with your particular development requirements, you can easily add more methods to the class, or rewrite the existing ones.
Now, by returning to the subject of this last installment, I’ll use the skeleton of the original “TemplateProcessor” class to develop an improved, production-level template processor, which, as you’ll see in a few moments, will be capable of working with multiple template files, in addition to implementing a chunked caching system. In this way, the class will be able to use several templates that have distinct cache expiration times, aside from utilizing most of the template processing features that you learned before.
Are you ready to start learning how to code this improved template processor? Right, let’s do it together.
| | 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! | | | | | |
|
 |
|