vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Why can't I preregister a template variable in a function? (https://vborg.vbsupport.ru/showthread.php?t=316713)

nerbert 01-16-2015 11:51 PM

Why can't I preregister a template variable in a function?
 
I got started on a project to make the What's Going On box available on pages other than the home page. The way I wanted to do it is shown schematically below:

Code:

 
function whats_going_on($template_name)
{
    global $vbulletin, $show, $template_hook, $vbphrase;
    .
    .
    .
    $templater = vB_Template::create('whatsgoingon');
    .
    $preregistered['whatsgoingon'] = $templater->render();
    vB_Template::preRegister($template_name, $preregistered);
}

whats_going_on('FORUMDISPLAY');

Well, that didn't work so I ended up doing it like this:

Code:

 
function whats_going_on()
{
    global $vbulletin, $show, $template_hook, $vbphrase;
    .
    .
    .
    $templater = vB_Template::create('whatsgoingon');
    .
    return $templater->render();
}

$preregistered['whatsgoingon'] = whats_going_on();
vB_Template::preRegister('FORUMDISPLAY', $preregistered);

What am I doing wrong that preregistering doesn't work inside a function?

kh99 01-17-2015 01:10 PM

I tested it out and for me it seems to work either way.

nerbert 01-17-2015 01:13 PM

What hook location were you using?

kh99 01-17-2015 01:24 PM

Well, forumhome_start, because I originally got confused between forumdisplay and forumhome and couldn't get it to work either way. Then when I figured that out I just decided to change everything to FORUMHOME. So I suppose I could try with FORUMDISPLAY in case that makes a difference.

Edit: no, it still works both ways, using FORUMDISPLAY and hook forumdisplay_start.

nerbert 01-17-2015 02:15 PM

If it's a Works-for-Peter-but-not-for-Paul situation I guess I better use what I have. I'm just tossing this product out for whoever wants to play with it and I don't want to have to help people write special code to get it going.

Thanks for testing it.


All times are GMT. The time now is 02:28 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.01086 seconds
  • Memory Usage 1,716KB
  • 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