Question: Is this possible?

From: Date: Tue, 14 Jan 2003 15:07:15 +0000
Subject: Question: Is this possible?
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-3299@lists.php.net to get a copy of this message
I would like to have it such that the common PHP code for files lives in a certain directory. I am able to do that already with the use of "include_once file.php". What I would like to know if its possible to do the following? I want to be able to pass the template around so that I can add elements to it. When I am finished I want to show it. I am trying to minimize having to maintain multiple copies of code. <Template> index.tpl.html ------------------------ <html> {menu_js} <body> {menus} </body> </html> <PHP Code> index.php ------------------------- require_once "HTML/Template/IT.php"; include_once 'includes/secrets.inc.php3'; include_once 'includes/menu.inc.php3'; // Data Source Name: This is the universal connection string $dsn = "mysql://$user:$pass@$host/$db_name"; // Database connect $db = DB::connect($dsn); // Load template $tpl = new HTML_Template_IT("./templates"); $tpl->loadTemplatefile("index.tpl.html",true, true); generate_menu_js($tpl); generate_menus($db, $tpl); $tpl->show(); $db->disconnect(); <Menu> menu.inc.php3 ---------------------------- function generate_menu_js (&$tpl) { $line = ... Menu javascript code ... $tpl->setCurrentBlock("menu_js"); $tpl->setVariable("menu_js", $line); $tpl->parseCurrentBlock("menu_js"); } function generate_menus (&$db, &$tpl) { $result = ... result of db query $line = ... menu items create from result items $tpl->setCurrentBlock("menu"); $tpl->setVariable("menu", $line); $tpl->parseCurrentBlock("menu"); } <END Result> <html> <!-- Javascript --> <script ...></script> <body> <!-- Menus --> <a href ...></a> </body> </html> Stephen -- Stephen Torri <storri@sbcglobal.net>

Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
« previous php.pear.general (#3299) next »