The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
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. |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
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 |
#4
|
|||
|
|||
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. |
#5
|
|||
|
|||
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.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|