Ok, I have played around with templates and have successfully pieced together a functioning system based on several others. As a newbie just starting out I am certain it can be improved upon and now I am looking for comments that will guide me in the right direction. As I had stated in my first post my goal was to work off of phpBBs template concept of using a language file ...
To actually get it working I have two seperate classes one for header and footer - I'm convinced thats not the best way to do it. :lol: I think I might also want to incorporate a cache function in it as well <hint-hint>
index.php
<?php
require_once('ST_Language/Lang_MySite.php');
require_once('ST_Includes/Template.php');
$header = new Header('ST_Templates/overall_header.tpl');
$header->replace_tags(array(
'L_HOMELINK' => $lang['HomeLink'],
'L_DEVICELINK' => $lang['DeviceLink'],
'L_SOFTWARELINK' => $lang['SoftwareLink'],
'L_REVIEWLINK' => $lang['ReviewLink'],
'L_NEWSLINK' => $lang['NewsLink'],
'L_FORUMLINK' => $lang['ForumLink'],
'L_COMPLINK' => $lang['CompLink'],
'L_LINKSLINK' => $lang['LinksLink'],
'L_MOBILELINK' => $lang['MobileLink'],
'L_SLOGAN' => $lang['Slogan'],
'U_HOMELINK' => $lang_URL[' '],
'U_DEVICELINK' => $lang_URL[' '],
'U_SOFTWARELINK' => $lang_URL[' '],
'U_REVIEWLINK' => $lang_URL[' '],
'U_NEWSLINK' => $lang_URL[' '],
'U_FORUMLINK' => $lang_URL[' '],
'U_COMPLINK' => $lang_URL[' '],
'U_LINKSLINK' => $lang_URL[' '],
'U_MOBILELINK' => $lang_URL[' ']));
$header->output();
include('ST_Content/index_body.tpl');
$footer = new Footer('ST_Templates/overall_footer.tpl');
$footer->output();
?>
Template.php - working version has duplicated this class but renamed everything "footer" - hahaha!
<?php
class Header
{
var $header;
function Header($template = 'overall_header.tpl')
{
if (file_exists($template))
$this->page = join('', file($template));
else
die("Template file $template not found.");
}
function parse($file)
{
ob_start();
include($file);
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
function replace_tags($tags = array())
{
if (sizeof($tags) > 0)
foreach ($tags as $tag => $data)
{
$data = (file_exists($data)) ? $this->parse($data) :
$data;
$this->page = eregi_replace('<tag:' . $tag . ' />', $data,
$this->page);
}
else
die('No tags to replace.');
}
function output()
{
print($this->page);
}
}
// I duplicated everything above creating a new class "footer" ...
?>
The language file (Lang_MySite.php) and the template file (overall_header.tpl) are pretty basic and as such self explanatory so I have not included them here.
So what suggestions do you have? Do I actually need a 2nd class for the footer call?
I look forward to your tips.