If you're maintaining a legacy PHP application which suffers from mixing of application logic and presentation, you may want to implement a simple template system to help separate these two.
Of course there are plenty of existing PHP templating systems, with Smarty being one of the most 'notorious' ;-). But if you have simple needs and don't want to introduce external dependencies to your code, rolling your own simple system can make sense. Let's face it -- you can often roll your own in the time it takes to figure out someone else's system.
Here are several posts which I found useful in this regard :
A good, clean, full overview of a simple OO (object-oriented) template system, written in 2008 :
A full treatment of a simple OO template system, compatible with PHP 4, written in 2005. Part II includes a simple caching system :
- Building a Template Parser Class with PHP, Part I
- Building a Template Parser Class with PHP, Part II
A good overview of a simple OO template system compatible with PHP 4, written in 2004. The above article written in 2005 is quite similar but perhaps explained better. Use the two-part article above before referring to this :