Log in

View Full Version : How to use variables created inside a hook


sv1cec
07-13-2005, 11:49 AM
I have created a hook, attached at location showthread_postbit_create, in showthread.php. The code in the hook does some calculations and returns some values to some variables, let's call them $show1, $show2 etc.

At the end of the hook, I check the variables, by echoing them, and they are correct. However, when I try to use them inside postbit template, they are empty. Is there a specific way to call these variables? I even tried making them global, still no luck.

Rgds and tnx

akanevsky
07-13-2005, 02:10 PM
I'd like to know that too.

Marco van Herwaarden
07-14-2005, 07:48 AM
Did you use a global before assigning the vaules?

akanevsky
07-14-2005, 11:50 AM
Did you use a global before assigning the vaules?
Is that required? It would be nice if they did those variables auto-global... Like they are in the templates.

sv1cec
07-15-2005, 09:18 AM
Unfortunatelly yes, you have to declare them as global, as I find out.

akanevsky
07-15-2005, 10:30 AM
Really? Crap. Well then, it would be IMHO the best to use those variables as $GLOBALS['var']

its less clutter than

global $var;
$var =

Andreas
07-16-2005, 01:27 AM
Another possibility:

In the Hook:
$vbulletin->foo = 'bar';

In the Postbit
{$this->registry->foo}