Forum Moderators: coopster

Message Too Old, No Replies

A template system

w/ block support

         

ATLien

8:56 pm on Jul 4, 2005 (gmt 0)

10+ Year Member



Hello, I have been using [codewalkers.com ] 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: [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.

dreamcatcher

10:25 pm on Jul 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World ATLien.:)

Actually, that class on Codewalkers isn`t so good. It fails with certain data. I would suggest you try Smarty or Savant.

dc

ATLien

4:15 am on Jul 5, 2005 (gmt 0)

10+ Year Member



thanks for the reply. I would prefer to generate my own template system. Do you know anyone who might be able to help me, a place where I can find one, or a simple on that I can use for referance?

dreamcatcher

11:02 am on Jul 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, to be honest there are lots of template systems around. As a lot of people don`t believe in re-inventing the wheel, finding tutorials might not be that easy. I`m sure there are some around. Have you tried the PHP Scripts Repository?

Out of curiosity, any reason why you don`t want to something like Smarty, PHPLib, Fast Template or Savant?

vabtz

11:32 am on Jul 5, 2005 (gmt 0)



phpbb template engine alright too IMO

ATLien

1:55 pm on Jul 5, 2005 (gmt 0)

10+ Year Member



The phpbb system is exactly what I am looking for. Does anyone know where I could find a guide on that template syste. I would use that one if I could.

jatar_k

4:52 pm on Jul 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld ATLien,

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]

vabtz

6:37 pm on Jul 5, 2005 (gmt 0)



Well you can.. I use it in all my projects, with a few tweaks.

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.

lobo235

7:43 pm on Jul 6, 2005 (gmt 0)

10+ Year Member



I had not done anything with templates until I started a new job recently. They used Smarty and so naturally, I had to learn how to use it. I was surprised at how easy it was to use and I was happy to see that there is great documentation for it. Since then I’ve been using it on my personal sites as well because of how easy it is to work with and because of its caching abilities, etc. I highly recommend Smarty.

vabtz

10:24 pm on Jul 6, 2005 (gmt 0)



the thing I don't lie about smarty is its bloated IMO.

ergophobe

11:42 pm on Jul 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




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.

lobo235

4:33 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



Doing an arbitrary-depth list in any template system is going to require you to write some of your own code. I suggest that if you are going to be creating lists of this type frequently you should think about writing a Smarty plugin to handle this. If you are trying to seperate code from design, this seems like the best choice anyway because you would be writing a lot of code (template code) to accomplish something like this directly in the template. Writing a plugin would clean up your template quite a bit and allow more flexiblity.

Check out the documentation on Smarty Plugins here:

[smarty.php.net...]

vabtz

4:43 pm on Jul 7, 2005 (gmt 0)



I had the same problem with all the templates I have used. I ended up writing my own code for the phpbb template engine to do it.

jatar_k

4:46 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



my thoughts are that if I have to write my own code for a "templating solution" then it's not much of a solution.

might as well do my own coding and roll my own instead of trying to hack something else to do what I want.

vabtz

4:51 pm on Jul 7, 2005 (gmt 0)



I guess thats a good answer if you don't understand the template class your modifying or you like to reinvent the wheel.

lobo235

4:58 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



I work in an environment where I do little to no design. The designer that I work with does not know PHP or have any programming background but has learned how to use the smarty language to do most things that are not too complicated. The thing that makes Smarty invaluable in my situation is that I can write plugins to do some of the more complex tasks involving data structures like multi-dimensional arrays of objects which most people that don't have any programming experience can't comprehend easily. All the designer has to do when I write a plugin is know how to call the new plugin and give it the data it needs. This keeps me focused on programming and the designer focused on designing which saves both of us a lot of time.

vabtz

5:00 pm on Jul 7, 2005 (gmt 0)



[edit: feeling a bit grumpy today ]

ergophobe

7:04 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I didn't know about Smarty plugins.

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.

Timotheos

5:57 pm on Jul 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.