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
2010-04-19 06:13:50
+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
2010-04-19 06:15:24
+1 for the second option.
nickf
2010-04-19 06:16:17
Im working with Wordpress so Im not sure I can restructure the script with out a lot of work.
Thomas
2010-04-19 07:22:18
+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
2010-04-19 06:15:43
So how does this work? Am I loading the footer data first and then echoing it later?
Thomas
2010-04-19 07:02:05
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
2010-04-19 07:07:44
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
2010-04-19 07:21:10
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
2010-04-19 06:21:47