vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Variable works fine in postbit, but is empty in template called from postbit. (https://vborg.vbsupport.ru/showthread.php?t=319296)

idiolalias 06-30-2015 01:44 PM

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.

Lynne 06-30-2015 02:22 PM

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?

idiolalias 06-30-2015 02:28 PM

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

kh99 06-30-2015 02:41 PM

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.

idiolalias 06-30-2015 02:52 PM

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?

kh99 06-30-2015 02:54 PM

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.

idiolalias 06-30-2015 03:02 PM

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!


All times are GMT. The time now is 03:55 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00980 seconds
  • Memory Usage 1,726KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete