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

Reply
 
Thread Tools Display Modes
  #1  
Old 08-29-2012, 06:31 AM
haxcommunity haxcommunity is offline
 
Join Date: Jun 2008
Location: Virginia
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Preregistering & custom pages

Hey guys, I'm in the process of converting a few personal vb3 custom pages to be compatible with vb4, however, I've hit some problems when it comes to handling the conditionals in my templates. Before, I could use the variable names themselves inside conditionals, and I have read that I need to preregister them first.

I've tried making a plugin to preregister, and doing it inside my php file itself, but still no luck.
I was wondering if somebody wouldnt mind going over how this is done in custom pages so that I can hopefully fix my issue. Thanks.
Reply With Quote
  #2  
Old 08-29-2012, 11:16 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you're talking about custom templates that you're creating and rendering in your custom page, then you should just call register() between the create() and render() calls, like:
Code:
$template = vB_Template::create('some_template_name');
$template->register('myvariable', $myvariable);
print_output($template->render());


If you want to register a variable to a vb template, then you need to use preRegister, and it's probably best to do it in a plugin (especially if it's one of those like header, headinclude, or footer). Use hook parse_templates and code like:
Code:
if (THIS_SCRIPT == 'myscript')
{
   $myvariable1 = 'something';
   $myvariable2 = 'something else';
   vB_Template::preRegister('header', array('myvariable' => $myvariable, 'myvariable2' => $myvariable2));
}
Reply With Quote
Благодарность от:
haxcommunity
  #3  
Old 08-30-2012, 12:54 AM
haxcommunity haxcommunity is offline
 
Join Date: Jun 2008
Location: Virginia
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Will this also work say, if the variables have been declared in the php file that loads the page?
(the second method, that is). I already have the code to set the variables, along with plenty of other code already in the file and would like to try to avoid having to modify ALL the code since its only the templates that are working incorrectly.

Also, thanks for the helpful reply kh99
Reply With Quote
  #4  
Old 08-30-2012, 01:50 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you're trying to put things in the header, headinclude, headinclude_bottom, footer, or one of the ad templates, then the preRegister has to be done before any other templates are used (because those templates get rendered in one of the initialization functions, and after that it's too late). In vbulletin with no mods, you could do it in your custom page before you rendered any templates. But some mods might use templates earlier (in a hook that's called when global.php is included), so it's best if you could do it in hook parse_templates. That way you'd avoid future problems where you might install a mod and have things break.

If your script can do whatever it has to do to set those variables without including global.php, then you could include global.php later in the file (but I guess that's unlikely since you need global.php to use the database or the logged in user's data).

Edit: another possibility - the those templates I mentioned are rendered and kept in some global variables. You might be able to insert a place holder (like and html comment), and then do a str_replace() on the appropriate variable once you have the value.
Reply With Quote
  #5  
Old 08-30-2012, 02:43 AM
haxcommunity haxcommunity is offline
 
Join Date: Jun 2008
Location: Virginia
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks again for the help, I did manage to find a solution, it seems like variables from the php files are not passed to the plugin coding, however, functions are. So my workaround has been either creating getters, or by having the conditions for the variable excecuted in the plugin coding.
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 11:14 AM.


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.07401 seconds
  • Memory Usage 2,203KB
  • Queries Executed 13 (?)
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
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (1)post_thanks_box_bit
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_postinfo_query
  • fetch_postinfo
  • 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