I'm currently developing a CMS. I've incorporated a template system into the CMS. It is my own, not Smarty.
I was wondering how I would go about displaying the result of a multiple row resultset by using a template file. My system does load in values correctly. But I don't know how I would go about loops.
config.php
$content = array(
'{T_ADMIN_HOME}' => $text[$config['language']]['AdminHome'],
'{L_ADMIN_HOME}' => 'index.php?page=admin/index',
'{KEY_HEADER}' => $text[$config['language']]['KeyHeader'],
'{VALUE_HEADER}' => $text[$config['language']]['ValueHeader'],
);
$grabConfig = "SELECT * FROM config ORDER BY config_key ASC";
$grabConfig = mysql_query($grabConfig);
$content['{KEY}'] = array();
$content['{KEY_VALUE}'] = array();
$i = 0;
While ($c = MySQL_fetch_array($grabConfig)){
$i++;
$content['{KEY}'][$i] = $c['config_key'];
$content['{KEY_VALUE}'][$i] = $config['config_value'];
}
config.tpl
<div id="adminContainer">
<a href="{L_ADMIN_HOME}">{T_ADMIN_HOME}</a>
<div id="adminBody">
<div id="adminText">
<table width="100%" cellspacing="1" cellpadding="1" border="0">
<tr>
<th>{KEY_HEADER}</th><th>{VALUE_HEADER}</th>
</tr>
<!-- CONFIG KEY LOOP -->
<tr>
<td>{KEY}</td><td>{KEY_VALUE}</td>
</tr>
<!-- END CONFIG KEY LOOP -->
</table>
</div>
</div>
</div>
How the values are loaded in. Where $body['Body'] is equal to the TPL file
foreach($content as $v => $c){
$body['Body'] = str_replace($v, $c, $body['Body']);
}
Above I make the items to be looped as an array. The only problem I'm having is how I would repeat the appropriate lines in the TPL file.
Thanks,
Edited by Lang, 10 February 2007 - 11:48 PM.
