Using a Template Processor Class in PHP 5 (
Page 1 of 4 )
Welcome to part two of the series “Separating logic from presentation.” Comprised of three articles, this series walks you through the development of an extensible template processor in PHP 5, which you might find quite useful for separating the logic of your PHP applications from their visual presentation.Introduction
As you’ll know (and assuming that you already took a look at the first article of the series), in the first tutorial I explained how to build in a PHP 5-driven template processor class. It exposed a few handy methods aimed at parsing the respective template file passed as an argument, by replacing its placeholders with actual data provided as an array structure.
If the above concepts are quite familiar to you, then you’ll recall that I provided my template processor class with certain interesting features, such as the ability to recursively replace placeholders, parse dynamic PHP files, process MySQL result sets, and run PHP code included as part of the input tags array. Of course, as I said before, the class can be easily expanded, either by defining more methods or modifying the existing ones, in order to fit the particular requirements of more demanding applications. As in most cases, deciding when and how to expand the template processor class will depend on the size and complexity of the Web project where the class will be included.
Now, bringing our attention to this second installment of the series, I’ll show you how to use the template processor class by coding some sample codes, so you can have an exact idea of how to include this class either in your own PHP projects or as part of a larger shared application.
Having defined the goals for this article, let’s leap forward and begin learning more about how to take advantage of this PHP 5 template processor class. Let’s go!
| | Discuss Using a Template Processor Class in PHP 5 | | | | | | | In this tutorial, the template processor I developed during the previous article is... | | | | | | Hi Alejandro,
I have read many of your articles and have found all of them an... | | | | | | Hi there,
Thank you for your comments on my PHP article, as well as your kind... | | | | | | Alejandro, That one doesn't work either?? I know practically nothing about regular... | | | | | | Hello again,
Sorry to hear about the syntax error again, but I used the class... | | | | | | I got the same syntax error above - and like many find regular expressions rather... | | | | | | 2 with reference to the above error - the problem is not in the regular expression... | | | | | | First off, I'd like to thank you for commenting on my PHP article. And lastly, with... | | | | | | just another note, the compressed html regex needs to escape for the line breaks... | | | | | | Thank you for posting some improvements on the template parser class, since they're... | | | | | | i tried the suggestion but it did not work so i edited it to (\r\n|\n) and it... | | | | | | Thanks alejandro for the wonderful code, it took me a whole night of anylizing where... | | | | | | Thank you for commenting on my PHP article. I see you modified the source code of... | | | | | | Thank you for commenting on my PHP article. The correct regexp is the one you used,... | | | | | | >>> Post your comment now! | | | | | |
|
 |