Forum Moderators: coopster
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: [codewalkers.com ]
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.
Out of curiosity, any reason why you don`t want to something like Smarty, PHPLib, Fast Template or Savant?
I don't know of a guide specifically for the phpbb system of templating but it does work like most, the logic of templating or skinning is fairly straight forward. I would imagine the phpbb one is too much for what you need anyway as you are using it for a specific site so you don't need something that is built to handle every eventuality.
Maybe take a look at this thread, it may give you some ideas.
A dynamic site in 2 minutes [webmasterworld.com]
Last I checked, there was a guide in their docs/faq section but, as with most things related to phpbb, it wasn't terribly good.
I highly recommend Smarty.
Then maybe your the person to answer the questions I raised here:
[webmasterworld.com...]
both general and specific. If it's as hard as I think it is to do something basic like arbitrary-depth nested lists with Smarty, then I'm still just not getting the advantage.
Database abstraction makes total sense. Templating makes total sense. But Smarty just hasn't sold itself to me yet.
Check out the documentation on Smarty Plugins here:
[smarty.php.net...]
I love the *idea* of Smarty - performance issues aside, I think abstraction is great. I just haven't quite managed to get convinced to get on board with Smarty.
I've been playing a bit lately with the Xaraya CMS which has a ADODB-like database abstraction layer and a Smarty-like templating system. It's a neat system to work with, but wow is there a lot of overhead - sssslllllooooooooowwwwwwwww.
I've been playing a bit lately with the Xaraya CMS which has a ADODB-like database abstraction layer and a Smarty-like templating system. It's a neat system to work with, but wow is there a lot of overhead - sssslllllooooooooowwwwwwwww.
One of the reasons the Drupal CMS switched to a php based template system.