Templating Problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

arctic2002
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Mar 03, 2003 11:44 pm

Templating Problem

Postby arctic2002 » Mon Mar 03, 2003 11:55 pm

Hi guys!

I'm new to the board, as well as PHP. My friend gave me some coding for templating a section of my site for all of my pages.

I made an html file called layout.tpl, containing the HTML.
And to view a specific page, called http://www.chariot32.com/demo/index.php?page=about.html (for future reference)

However, it doesn't load about.html, nor does it open other pages that I've created. I'm not quite sure how to go about and fix this b/c I'm a noob to this stuff. :P

<?
/// Quick 'n Dirty Template Class

class Template {
var $filename;
var $vars;

function Template($filename) {
if (empty($filename)) return;
$this->filename = $filename;
}

function addVar($key, $val="") {
if (is_array($key)) foreach ($key as $k=>$v) $this->vars[$k] = $v;
else $this->vars[$key] = $val;
}

function getContent() {
$contents = join('',file($this->filename));
if (!empty($this->vars)) foreach ($this->vars as $key=>$val) $contents = preg_replace("/\{$key\}/", $val, $contents);
return $contents;
}

function showFile() {
$contents = $this->getContent();
echo $contents;
}
}

if (empty($_REQUEST["file"])) $_REQUEST["file"] = "index.html";

$tpl =& new Template("layout.tpl");
$content = join('',file($_REQUEST["file"]));
$tpl->addVar("content",$content);
$tpl->showFile();

?>



-Arctic

arctic2002
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Mar 03, 2003 11:44 pm

Postby arctic2002 » Tue Mar 04, 2003 12:59 pm

If you have any other suggestions, thanks

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Wed Mar 05, 2003 3:55 am

If to me need a template system i'm use PatTemplate by php-tools.de


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 4 guests