PDA

View Full Version : access plugin variables from template


aviv_el
10-02-2011, 02:03 PM
I have a custom plugin I need to migrate from vb3 to vb4.
The plugin hooks to showthread_complete, runs various tests, and creates a variable.
Based on the value of the variable, the template displays or not certain blocks (ads, etc).

Idealy, for the sake of making things simple, I'd really like to use the same methodology- plugins runs checks, exposes variable to the template, template runs condition to check if value of variables, and accordingly display ads and rest of content.

Here's where I'm stuck: on showthread_complete hook, I can't really register the variable to the SHOWTHREAD template, as the in showthread.php the call to the showthread_complete hook is run before the declaration of $templater variable-
showthread.php code looks like this:
($hook = vBulletinHook::fetch_hook('showthread_complete')) ? eval($hook) : false;

// ################################################## ###########################
// output page
$templater = vB_Template::create('SHOWTHREAD');
$templater->register_page_templates();

$templater->register('pagenumbers', fetch_start_end_total_array($vbulletin->GPC['pagenumber'], $perpage, $totalposts));
$templater->register('totalposts', $totalposts);

Can anyone help?

EXIDE
10-02-2011, 02:06 PM
<a href="https://vborg.vbsupport.ru/showthread.php?t=228078" target="_blank">https://vborg.vbsupport.ru/showthread.php?t=228078</a>

That article will help.

aviv_el
10-02-2011, 03:09 PM
Exide, thanks for your reply.
However, I have a simple plugin hooked at showthread_complete:
vB_Template::preRegister('showthread', array(
'my_var' => 'my_var',
'my_array' => 'my_array'
)
);

And then, on SHOWTHREAD template I added:
{vb:raw my_var}
{vb:raw my_array}

I get nothing.
(as per David's advice (https://www.vbulletin.com/forum/entry.php/2387-Pushing-your-variables-to-vBulletin-4-templates))
Any idea??

EXIDE
10-02-2011, 04:15 PM
Template names need to match in the plugin.


vB_Template::preRegister('SHOWTHREAD', array(
'my_var' => 'my_var',
'my_array' => 'my_array'
)
);

aviv_el
10-03-2011, 11:31 AM
Thanks-
Writing capital letters rather than lower case made it work!