vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Preregistering & custom pages (https://vborg.vbsupport.ru/showthread.php?t=287225)

haxcommunity 08-29-2012 06:31 AM

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.

kh99 08-29-2012 11:16 AM

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));
}


haxcommunity 08-30-2012 12:54 AM

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 :D

kh99 08-30-2012 01:50 AM

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.

haxcommunity 08-30-2012 02:43 AM

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.


All times are GMT. The time now is 05:05 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.01102 seconds
  • Memory Usage 1,717KB
  • 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
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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