hey i'm new to templates but find them quite interesting because of the way they work, and i've come across a bit which baffles me.
i have several pages which all make the final page, and i want to use a while loop to display all of my news items, using a template for the items it self (message.tpl)
however i was wondering how do i get each part of the while loop in my variable {PAGECONTENT} which will then be outputted using body.tpl
here is my while loop
<?
$sql = "SELECT * FROM `stories` ORDER BY `id` DESC LIMIT 0,10";
$query = mysql_query($sql, $conn) or die(mysql_error());
while($story = mysql_fetch_array($query)) {
$string = $story['story'];
$string = format('1', '1', '1', '1', $string);
$headline = $story['headline'];
$writer = $story['writer'];
$person = strtolower($writer);
$tpl -> set_var(array(STRING => $string,
HEADLINE => $headline,
WRITER => $writer,
PERSON => $person));
}
?>
here is body.tpl
<center>
<a href="http://www.theutherfish.com/"><img src="./images/banner.gif" border="0"></a>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="700" id="AutoNumber1" bgcolor="#DDDDDD">
<tr>
<td width="15">
<img border="0" src="./images/tl.gif"></td>
<td width="670">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
<tr>
<td width="100%" height="1" bgcolor="#000000"></td>
</tr>
<tr>
<td width="100%" height="14"></td>
</tr>
</table>
</td>
<td width="15">
<img border="0" src="./images/tr.gif"></td>
</tr>
<tr>
<td width="15" height="100%">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3" height="100%">
<tr height="100%">
<td width="1" bgcolor="#000000" height="100%"></td>
<td width="14" height="100%"> </td>
</tr>
</table>
</td>
<td width="670">
<table align="center" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
<tr align="center">
<td width="100%" align="center"><br>{ADVERT}<br><br></td>
</tr>
<tr>
<td bgcolor="#000000" cellpadding="0" cellspacing="0">
<table width="100%" cellpadding="0" cellspacing="1">
<tr align="center" bgcolor="#EEEEEE">
<td width="100%">
<table width="100%" cellpadding="0" cellspacing="0" class="user">
<tr><td><table cellpadding="0" cellspacing="0" width="100%"><tr>{MENU}</tr></table></td></tr>
<tr>
<td style="border-bottom-width: 1px; border-bottom-style: dashed;" bordercolor="#000000"><p><a href="http://www.theutherfish.com/" class="bread">theutherfish.com</a><font class="bread"> > {LOCATION}</td>
</tr>
<tr>
<td width="100%" align="left"><br><p><font class="user">
{PAGECONTENT}
<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr align="center">
<td width="100%">{footer_out}</td>
</tr>
</table>
</td>
<td width="15" height="100%">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber5" height="100%">
<tr height="100%">
<td width="14" height="100%"> </td>
<td width="1" bgcolor="#000000" height="100%"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15">
<img border="0" src="./images/bl.gif"></td>
<td width="670">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber4">
<tr>
<td width="100%" height="14"></td>
</tr>
<tr>
<td width="100%" height="1" bgcolor="#000000"></td>
</tr>
</table>
</td>
<td width="15">
<img border="0" src="./images/br.gif"></td>
</tr>
</table>
</body>
</html>
and here is the page where everything is loaded
<?
session_start();
include ("includes/template.inc");
include ("includes/functions.inc");
include ("includes/common.inc");
$sql = "SELECT * FROM `pageinfo` WHERE `page`='".$_SERVER['SCRIPT_NAME']."'";
$qry = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_array($qry);
$index = $row['update'];
$sql = "SELECT * FROM `update` WHERE `id` = '$index' LIMIT 0,1";
$query = mysql_query($sql, $conn) or die(mysql_error());
$test = mysql_fetch_array($query);
if ($test['updating'] == '1') {
$url = "http://www.theutherfish.com/update.php";
die(Header('Location: '. $url));
}
$tpl = new Template("templates", "remove");
$tpl -> set_file(array(
"header" => "header.tpl",
"footer" => "footer.tpl",
"style" => "style.tpl",
"body" => "body.tpl"));
$menuitem = $row['menu'];
$tpl -> set_var(ADVERT, ad_banner());
$tpl -> set_var(MENU, menu($menuitem));
$title = $row['pagename'];
if($title=='' || !isset($title)) {
$tpl -> set_var(TITLE, "theutherfish.com - [Home] - the best thing since sliced bread");
}
else {
$tpl -> set_var(TITLE, "theutherfish.com - [".$title."] - the best thing since sliced bread");
}
$location = $row['pagename'];
if($location=='' || !isset($location)) {
$tpl -> set_var(LOCATION, "Home");
}
else {
$tpl -> set_var(LOCATION, $location);
}
$tpl -> parse("header_out", array("style", "header"));
$tpl -> parse("footer_out", "footer");
$tpl -> parse("body_out", "body");
$tpl -> p("header_out");
$tpl -> p("body_out");
?>
if this is not possible i would appreciate any suggestions on how to get round this
thanks, Comms