Page 1 of 1

Functions, Output Buffering, Templating and Variable usage

Posted: Thu Mar 06, 2008 1:52 pm
by linchay
Hi all,

I have been working on a templating system and have a development strategy (scheming) question. The template system is tag based and will include files based on certain tags.

To achieve this I have written a parser class which parses the page and loads file via output buffering.

The nature of this creates some positives and negatives. The plus is items are compartmentalized, the drawback is that none of the variables loaded with each file are available to others included files due to loading within the class/function.

I was wandering how other developers handled this issue? Singletons, Global variables or what? :)

Schematic
Client Requests -> *conductor -> parse requested page -> parse template -> fuse pages

*conductor is always loaded. I have a regex alias written in apache that grabs all requests and only loads a file called conductor.inc. This file is a preloader and basically handles the site.

The main problem is that since "requested pages" are loaded first that information is not available to the template because each file was individually loaded by a function which seals the varialbles into the pages local scope. How would you deal with sharing variables in this situation?

Re: Functions, Output Buffering, Templating and Variable usage

Posted: Tue Apr 01, 2008 9:05 am
by samb0057
In my system I have an $args argument to the function, and pass anything through there.

function displayTemplateStuff($a, ..., $args) {
ob_start();
require('myfile');
return ob_get_clean();
}

You can also make that argument a reference, so that the included templates can make changes to it.