HTML_Template_IT question
| From: | Stephen Torri | Date: | Sat, 01 Feb 2003 02:49:24 +0000 |
| Subject: | HTML_Template_IT question | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-3535@lists.php.net to get a copy of this message | ||
I have a template below that is used by index.php (main page for the web
site). I am creating an instance of the HTML_Template_IT class giving
the file name. What I try to do is pass the HTML_Tempalte_IT variable by
reference to the function generate_menu_html and generate_menu_css. The
function 'generate_menu_css' is suppose to handle the placeholder
'{css}' while 'generate_menu_html' is to handle '{menu}'. The
resulting
code is not what is expected. Below is the results of running the code
as it stands right now, what is the expected behaviour, template and php
code. I decided to err on the side of providing a lot of information
rather than have people trying to decipher what I am doing.
Stephen
----------- Results ----------------
<html>
<script language='Javascript1.2' src='menu.js'
type='text/javascript'></script>
<script language='Javascript1.2' type='text/javascript'>
var linkset = new Array();
</script>
<body>
<!-- Note: Main table -->
<table width="100%" border="0" cellpadding="0"
cellspacing="0">
</table>
<!-- end Main table -->
</body>
</html>
<html>
<body>
<!-- Note: Main table -->
<table width="100%" border="0" cellpadding="0"
cellspacing="0">
<div id='popmenu' class='menuskin'
onMouseover='clearhidemenu();highlightmenu(event,'on')'
onMouseout='highlightmenu(event,'off');dynamichide(event)'>
</div>
<a href='#' onMouseover='showmenu(event,linkset[0])'
onMouseout='delayhidemenu()'></a>
<a href='#' onMouseover='showmenu(event,linkset[1])'
onMouseout='delayhidemenu()'></a>
<a href='#' onMouseover='showmenu(event,linkset[2])'
onMouseout='delayhidemenu()'></a>
<a href='#' onMouseover='showmenu(event,linkset[3])'
onMouseout='delayhidemenu()'></a>
<a href='#' onMouseover='showmenu(event,linkset[4])'
onMouseout='delayhidemenu()'></a>
</table>
<!-- end Main table -->
</body>
</html>
----------- Expected ---------------
<html>
<script language='Javascript1.2' src='menu.js'
type='text/javascript'></script>
<script language='Javascript1.2' type='text/javascript'>
var linkset = new Array();
</script>
<body>
<!-- Note: Main table -->
<table width="100%" border="0" cellpadding="0"
cellspacing="0">
<div id='popmenu' class='menuskin'
onMouseover='clearhidemenu();highlightmenu(event,'on')'
onMouseout='highlightmenu(event,'off');dynamichide(event)'>
</div>
<a href='#' onMouseover='showmenu(event,linkset[0])'
onMouseout='delayhidemenu()'></a>
<a href='#' onMouseover='showmenu(event,linkset[1])'
onMouseout='delayhidemenu()'></a>
<a href='#' onMouseover='showmenu(event,linkset[2])'
onMouseout='delayhidemenu()'></a>
<a href='#' onMouseover='showmenu(event,linkset[3])'
onMouseout='delayhidemenu()'></a>
<a href='#' onMouseover='showmenu(event,linkset[4])'
onMouseout='delayhidemenu()'></a>
</table>
<!-- end Main table -->
</body>
</html>
----------- Template index.tpl.html ---------------
<html>
{meta_info}
{menu_js}
{css}
<body>
<!-- Note: Main table -->
<table width="100%" border="0" cellpadding="0"
cellspacing="0">
{title_bar}
{menu}
{google}
{content}
</table>
<!-- end Main table -->
</body>
</html>
{signature}
-------------- Index.php ---------------
<?php
include_once "DB.php";
require_once "HTML/Template/IT.php";
include_once 'includes/secrets.inc.php3';
//include_once 'includes/meta.inc.php3';
//include_once 'includes/signature.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);
// {meta}
// Set meta info
//generate_meta($tpl);
// {css}
//$tpl->setCurrentBlock("css");
// Put stylesheet info into variable
//$tpl->parseCurrentBlock("css");
// {title}
generate_menu_css($tpl);
generate_menu_js($tpl);
generate_menu_html($db, $tpl);
// {menu}
// {google}
// {content}
// {signature}
// Set Signature
//generate_signature($tpl);
$tpl->show();
// You can disconnect from the database with:
$db->disconnect();
?>
------ Functions used (generate_menu_css and generate_menu_html) -----
<?php
include_once "DB.php";
// generate menu css
function generate_menu_css (&$tpl) {
$line = "<link rel='stylesheet' href='css/menu.css'
type='text/css'>\n";
$tpl->setCurrentBlock("menu_css");
$tpl->setVariable("menu_css", $line);
$tpl->parseCurrentBlock("menu_css");
}
function generate_menu_html (&$db, &$tpl) {
$line = "<div id='popmenu' class='menuskin'
onMouseover='clearhidemenu();highlightmenu(event,'on')'
onMouseout='highlightmenu(event,'off');dynamichide(event)'>\n";
$line .= "</div>\n";
$sql = "select * from menus where Parent_Index = 0";
$result = $db->query($sql);
if (DB::isError($result)) {
die ("Query Failed: $sql: ".$result->getMessage());
}
$counter = 0;
while ($row = $result->fetchRow()) {
$line .= "<a href='#' onMouseover='showmenu(event,linkset[" .
$counter . "])' onMouseout='delayhidemenu()'>";
$line .= $row[description] . "</a>\n";
$counter += 1;
}
$tpl->setCurrentBlock("menu");
$tpl->setVariable("menu", $line);
$tpl->parseCurrentBlock("menu");
}
?>
--
Stephen Torri <storri@sbcglobal.net>
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc