vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   access plugin variables from template (https://vborg.vbsupport.ru/showthread.php?t=271290)

aviv_el 10-02-2011 02:03 PM

access plugin variables from template
 
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:
Code:

($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:
Code:

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

And then, on SHOWTHREAD template I added:
Code:

{vb:raw my_var}
{vb:raw my_array}

I get nothing.
(as per David's advice)
Any idea??

EXIDE 10-02-2011 04:15 PM

Template names need to match in the plugin.

PHP Code:

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!


All times are GMT. The time now is 11:08 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.01100 seconds
  • Memory Usage 1,722KB
  • 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
  • (3)bbcode_code_printable
  • (1)bbcode_php_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