Posted on: 10/04/07 10:10pm
By: jmucchiello
PHP was created so people could create websites by mixing code right in the HTML. When designers decided that mixing business logic with presentation was a bad thing, rather than using disciplined coding techniques to avoid that pitfall, the template library was born. So, an interpreted language designed to create HTML was being used to interpret template files to make HTML.
This hack attempts to make templates faster by turning them back into PHP. The existing templates are converted into working PHP code and stored in a cached directory. "Running" the template becomes as easy as "include"ing the cached file.
GoalsThat's almost it. The aim was to minimize the impact on core code. That was done but minimize doesn't mean no codes are needed. There are some places in the core code (and in many plugins) where a buggy feature of the old template library was being taken advantage of.
Basically, the new lib replaces template variables by turning them into php code that is executed. This is fast but it also can run afoul of sloppy coding. There are several places in core Geeklog where template variables are set AFTER the call to parse(). This is a bug based on the way the library is supposed to work but since the variable remains in the text stream, it get replaced during the final parse. This library isn't as forgiving. Basically, some lines of code need to be reordered so the library will produce the "expected" output. The author of MediaGallery helped me clean up this code in his plugin and he found many bugs in MG that will be fixed in its next release. So while this library is not compatible with MG at the moment, it will be with the next release of MG. Mark is running this library on his live gllabs.org site so by now the new template class should be pretty solid. One forum issue is noted below but there are probably other issues. And I have not gone around fixing all the other plugins that may suffer from these bugs. I don't advise using this library on your live webpage unless you are able to find these kinds of bugs and fix them. The easiest fix for screens that don't look right is to set $_CONF[] to false. This turns off the new library completely. The next easiest method is to replace the "new Template" to a call to COM_newTemplate() setting $use_old_class to true: $T = new Template('.../some/root/path'); becomes: $T = COM_newTemplate('.../some/root/path', 'remove', true); What's the point of this hack? Well, I want it out there. Hopefully it will become part of Geeklog core in the future.
Additional FeaturesJoe Mucchiello can be contacted by email: joe at throwingdice dot com Original PHPLIB documentation can be found using your favorite web search engine.
Thanks to Michael Jervis for doing some permformance checks on the proof-of- concept version of this library showing that it was faster than the base library. Without that I never would have spent the time polishing this library.
Thanks to Mark R. Evans for really helping shake out the bugs, doing performance checks, and for basically beta testing the library on his live website: http://www.gllabs.org
Posted on: 10/05/07 12:17am
By: mevans