The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Plugin variable not showing in postbit data
Background:
I've created a userfield which contains the number of times a forum member has won an award (in this case an oven mitt). I'm trying to display a graphic in postbits for each time the winner has won. So if a member has won 3 oven mitts then the field contains 3 and it should display the graphic 3 times. I've written some plugin code that creates a variable with an oven mitt image. I did this because I was unable to use a for loop in the postbit template. Here is the plugin code that creates the oven mitt image data: Code:
global $vbulletin; if ($vbulletin->userinfo['userid'] == 1) { $ovenmittcount = $vbulletin->userinfo['field12']; $ovenmitts = ""; for ($loopcount=1; $loopcount<=$ovenmittcount; $loopcount+=1) { $ovenmitts = $ovenmitts . '<img src="http://www.badbeatspoker.net/images/isopmitt.jpg">'; } } In forumdisplay this code shows the image correctly: Code:
<center> $random_banner[$random_number] $ovenmitts </center> I've tried setting the plugin to work in global_start and a variety of other showthread and postbit hooks with no joy. This is the code I'm using in postbit: Code:
<if condition="$post['field12']"> $ovenmitts </if> |
#2
|
|||
|
|||
I think the problem is that unless the variable is declared global (where it's set and where the template is eval'ed), it will be undefined and so will appear to be 0. That's a problem when doing what you're doing - you pretty much need to go in to the code to see what's going on, and find out where the template is eval'ed and where your hook is executed. In the case of postbit it looks like the template is used in includes/class_postbit.php in the function construct_postbit around line 304. I see that just above that is the "postbit_display_complete" hook, so probably the easiest thing would be to try using that hook.
|
#3
|
|||
|
|||
I tried that hook per you suggestion and it still doesn't display. Is there a way to declare my ovemitts variable global? I've tried putting global in front of it as the first line of the plugin like so:
Code:
global $ovenmitts; Do I need to declare this as global in the class_postbit.php file? |
#4
|
|||
|
|||
Hmm...sorry, I guess I was wrong about something, just don't know what it is. There's no reason to edit class_postbit.php if putting it in the pluging didn't work.
So let's see - maybe that's not really where the template is used. You could try just putting an "$ovenmitts = something or other" in a plugin in using postbit_display_complete just to see if that's the right place. Are you sure "$post['field12']" is the right condition? If not, try taking the condition out temporarily. |
#5
|
|||
|
|||
the condition is right because I can put some random text in the the if statement and that prints as long as there is data in the field. The plugin code is correct because I can use the variable in forumdisplay and it works fine.
I thought it was a scope issue but I would have thought putting it in global_start would solve that. As a side note I noticed the random_banner code which posts an ad banner in forumdisplay correctly also does not display in the postbit template. I've removed the conditional in the postbit template just to make sure and still nothing. It is like the variable is blank. |
#6
|
|||
|
|||
Yeah, I know you'd have to have a "global" where the template is eval'ed (if it's in a function call), but it could be that the place I mentioned is not the right place for that template.
Sorry. Maybe someone else knows? --------------- Added [DATE]1269010062[/DATE] at [TIME]1269010062[/TIME] --------------- ...oh, I did think of one thing - your plugin uses $vbulletin->userinfo['field12'] but I think you'd want $post['field12'], right? |
#7
|
|||
|
|||
The plugin generates the proper image into the $ovenmitts variable. I confirmed this by putting the variable into the forumdisplay template and it shows properly. I also did a couple diagnostic print statements in the plugin to make sure the $ovenmittcount varialbe was getting the correct number from the field12 variable.
Either the $ovenmitts varialbe is getting wiped, isn't scoped correctly or I'm not calling it correctly to display in the postbit template. I'm just not sure where to go from here. I appreciate your help though |
#8
|
|||
|
|||
Anyone else have some ideas that I can try?
|
#9
|
|||
|
|||
OK, well, I have another one - use $bbuserinfo['ovenmitts'] instead of $ovenmitts to get rid of the scoping issue. I think $bbuserinfo is the same as $vbulletin->userinfo, and I don't know where $bbuserinfo gets set, so it's possible you might have to set $vbulletin->userinfo['ovenmitts'] in the plugin and use $bbuserinfo['ovenmitts'] in the template. (If someone wants to explain more about the use of those, I'd like to know).
Anyway, it may not be the "correct" thing to do but I think it will work (assuming scoping is the issue). |
#10
|
|||
|
|||
I'll give it a shot. Thanks
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|