Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-30-2015, 01:44 PM
idiolalias idiolalias is offline
 
Join Date: May 2009
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Variable works fine in postbit, but is empty in template called from postbit.

hey,

I'm trying to do something from within the postbit that is basically: if condition 1, display template 1, if condition 2, display template 2, etc.. I need to be able to work with the typical postbit variables from within template 1 and template 2. Right now I have a custom template, "postbit_test", that I'm calling from within the postbit template, but I can't get postbit variables to show up inside it.

the variable $post[field2] shows up just fine in the postbit template, for example, but it's empty and displays nothing from within "postbit_test". I've tried $GLOBALS[post][field2] with various permutations of parentheses but that isn't doing me much good either. How do I go about calling these variables? I'm going to be attempting to do this with as many templates as possible so any information on how to pass these variables will be very helpful.

I'm on vb 3.8 for the record.

thank you.
Reply With Quote
  #2  
Old 06-30-2015, 02:22 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How are you calling postbit_test? Is this through a plugin? What hook are you using? Have you looked up the hook in the code and seen if it might be within a function?
Reply With Quote
  #3  
Old 06-30-2015, 02:28 PM
idiolalias idiolalias is offline
 
Join Date: May 2009
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm calling postbit_test via this "parse_templates" hook

PHP Code:
eval('$postbit_test = "' fetch_template('postbit_test') . '";'); 

and then just referencing $postbit_test from within the postbit template. Apparently I should be specifying which variables I want to pass before I make the call? I found this post which seems straightforward enough for a string and a custom variable. Do you know if vB variables will work similarly, or if there's a better way I should be doing it? I'm pretty much going to want the whole $post array available inside postbit_test, and probably $threadinfo and whatever else, too.

edit: nvm, I just tested and $threadinfo already works fine inside postbit_test

edit 2: actually, I lied, I reference $GLOBALS[postbit_test] within the postbit template
Reply With Quote
  #4  
Old 06-30-2015, 02:41 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The parse_templates hook is called once during initialization. If you want to use $post in something that's displayed in each postbit, you probably want to use hook postbit_display_complete.
Reply With Quote
Благодарность от:
Lynne
  #5  
Old 06-30-2015, 02:52 PM
idiolalias idiolalias is offline
 
Join Date: May 2009
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

shit, son. Okay, sweet.

I moved the eval from parse_templates to postbit_display_complete. I had to change $GLOBALS[postbit_test] to a plain $postbit_test inside the postbit template to display anything, but now I've got my postbit_test template showing up as normal, and the $post variables I was trying to reference are now working inside that template instead of empty. Awesome.

however, I can't reference $threadinfo variables any more, like I normally can from within postbit, and like I could before I changed the hook location. I'm trying to make use of this functionality, also. Any insight?
Reply With Quote
Благодарность от:
TheLastSuperman
  #6  
Old 06-30-2015, 02:54 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That hook is called inside a function (construct_postbit() in includes/class_postbit.php, if you want to look at the code), so you need to declare any global variables you want to use. But in the case of the thread info, there is a $thread variable there already.
Reply With Quote
Благодарность от:
Lynne
  #7  
Old 06-30-2015, 03:02 PM
idiolalias idiolalias is offline
 
Join Date: May 2009
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

lol. Whoops. Yeah, okay. The $thread variable suits my needs for now, guess I'll just worry about the rest next time I run into the issue. Thanks though!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:25 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06119 seconds
  • Memory Usage 2,228KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (3)post_thanks_box_bit
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete