views:

29

answers:

4

In the header of my page I have a conditional statement to check if $foo boolean is set, the trouble is that the $foo boolean doesn't get set until the footer is loaded. Any way to retroactively check the status of this boolean?

A: 

No. At least not an easy way. You would have to use a templating system that can run the output after the page has finished loading.

webdestroya
+3  A: 

You can't "retroactively" check a condition. Your best bet may be to have the footer function execute first and save the footer in a variable, then echo it later.

Or, better, restructure the script so that all the state is determined first, then the HTML is created.

deceze
+1 for the second option.
nickf
Im working with Wordpress so Im not sure I can restructure the script with out a lot of work.
Thomas
+2  A: 

You can buffer the output of the footer, then generate the header and output it first.

ob_start();
outputFooter();
$footer= ob_get_clean();

outputHeader();
outputBody();
echo $footer;
Matt
So how does this work? Am I loading the footer data first and then echoing it later?
Thomas
Yes. You are processing the footer like you normally would, but you are storing the result in the `$footer` variable rather than sending it to the browser. At that point you can echo that variable whenever you want, in this case.. after the header/body
Matt
Thats wierd, the buffer is working (since the footer is getting outputed correctly) but I still can't seem to detect whether or not the boolean has been set yet.
Thomas
Ooops, I got it - need to check my scope - thanks...
Thomas
A: 

Nope...Just a few alternatives, try refactoring the code to assure that value is being set first. Use session for setting the values may also be an option.

Hanseh