(Templating || Theming) + PHP == Output Buffering?

For a while now, I’ve been working on a framework that should, ultimatly, allow me to create a website by simply uploading the framework, modules the site needs, run a few installers and thats it. If it needs something I don’t have yet, I would be able to just write a new module without having to worry about things like sessions, users, etc, because the framework does that.
I did a few total rewrites, I’ve been verry unhappy about the way things work several times, but now I feel I’m really getting on my way.
There is just one thing left, really: A theme system. Its not that hard to just make a simple text-replacement system, but that just wouldn’t do. Partially because I want to give the person who makes it full control, so they need to be able to use PHP. And that, right there, makes it kinda hard. The theme/template file has PHP, so it needs to be parsed by the Zend Engine. (Sure, if I would really really really want to, I might be able to get the contents of the file, use a few dozen regular expressions, and be able to do basic PHP that way, but that would take ages to develop, ages to run, and would only allow basic PHP; I want it all.) However, when you do that, everything is outputted to the client (= whatever requested the page) rightaway, which I don’t want. (For several reasons. One being that I might need to set cookies, start sessions, etc after primary output. Another one is: The page title has to be partially set by the running module, but that would mean that the module is responsible for using the templating system, which I don’t want. All it should have to do is $this->engine->template(‘comments’);, and the framework would do everything else.)
Just now, I did find a solution: PHP’s output buffering system.
It wouldn’t be verry hard, I beleave. Consider the following function (as a part of the Framework’s engine class)
public function template( $what )
// The magic of grabbing the right file, executing it
$output = ob_get_contents();
return $output;

This, right now, seems to be the way to do this. However, I have never worked with PHP’s output buffering, and thus, have no idea if this would actually work as I want it to, how it is on speed / memory usage, etc.
So I gues thats really the point of this blogpost (other then posting. 😛 ), to find out of any of my nonexistant users is could give me some advice on the ob_ functions.

About Jory

Born in 1988, Software Engineer (BA), dutch. Will ad more later.
This entry was posted in Programming. Bookmark the permalink.

One Response to (Templating || Theming) + PHP == Output Buffering?

  1. Verminox says:

    I say just make your own API to give anyone who themes the site control over where the modules get to play, and where things should be the way they like. Or else it wouldn’t be customization if you are going to edit their stuff by shoving other stuff in the middle 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *