Hello, I have been using http://codewalkers.com/tutorials/58/1.html to create a template system for my upcoming site. The tutorial is great, I am just trying to expand the functionality to allow for blocks.
Original Class:
<?php
class Page
{
var $page;
function Page($template = "template.html") {
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 . "}", $data,
$this->page);
}
else
die("No tags designated for replacement.");
}
function output() {
echo $this->page;
}
}
?>
Execution of the class:
<?php
require_once("lib/template.php");
$page = new Page("template.html");
$page->replace_tags(array(
"title" => "HOME",
"descript" => "Welcome to my website!",
"main" => "dat/index.dat",
"menu" => "dat/menu.dat",
"left" => "dat/submenu.dat",
"right" => "dat/right.dat",
"footer" => "dat/footer.php"
));
$page->output();
?>
What I am trying to accomplish is the ability to use:
<!-- START logged_in -->
Code to display when logged in.
<!-- END logged_in -->
then link that to a if statment in the php so that section will display only if the logged in sessions are registered.
There is some more info and a attempt at doing this here: http://codewalkers.com/forum/index.php?action=displaythread&forum=tutorials&id=174&realm=default
I can't seem to make that work because that deals with loops, I am trying to just use it is a template style if statment.
I appreciate the help. This issue has been something I have worked on for days. The blocks need to be able to work with other types i.e. is_admin stuff like that. There also will be multiple blocks per page. I am not the best at php so anything you can tell me will help.
Here is another thread I asked for help in, and someone answered but I am not evanced enough to understand what they are saying.