Version: 1.0
Type: Class
Category: HTML
License: GNU General Public License
Description: Allows you to build pages from templates containing PHP (can be nested). Requires phplib's template class (template.inc) (normally installed by default I think). Some people may disagree with this class' existence, saying that the reason for templates is to separate HTML from PHP and keep HTML/frontend people out of coders' hair. Not for me. Since I do both design/HTML and PHP aspects of my project, the major benefit of templates has been a central point of control for the UI. This class means that I can modularise elements like 'search for a user' (which contain PHP) and re-use them in different pages. Since I'm working on a portal, it has the added bonus of elegantly facilitating user-customised UIs, where users could choose what elements appear where on their interface.
<?php
# File : Module.php
# Version : 1.0
# Written : Nick Doyle, 1/7/2002
# Description : Extension of the Template class to allow PHP code in templates
# (which I'm calling 'modules', extension '.iphp' following the standard of templates having extension '.ihtml')
# Note that if you have template variable-like strings in your php e.g. {CONTENT} this may get parsed/substituted,
# depending on how you're doing things
require_once( 'template.php');
class Module extends Template {
# Override the pparse function to evaluate the parsed code as php instead
# Evaulation is left till last and performed at print-out time, so the code is only sent to PHP to evaluate once
function pparse( $target, $handle, $append = false) {
eval( '?>' . $this->parse( $target, $handle, $append));
return false;
}
}
?>