vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Assistance with simple plugin - variable registering (https://vborg.vbsupport.ru/showthread.php?t=277386)

Mark.B 01-22-2012 03:46 PM

Assistance with simple plugin - variable registering
 
This should be so simple and I seem to get this every time.

I am trying to execute a query at global_start (or anywhere that's available to the header template). I know the query works as in the code below I echo out the result and it works.

What I can't do, is get the result output into the header template!


I know about registering variables, I've had that work before but once again despite numerous permutations this simply won't work.

I have even now tried using a non-existent template hook and then added that template hook into the header template - a trick I have used before to avoid the registering nonsense - but STILL it won't output.

Having tried about 436 different combinations of code, I'm now at a loss...can anyone tell me where I am going wrong?

I can echo $template_hook['status'] and it outputs correctly, but putting {vb:raw template_hook.status} into the template does nothing.

Code:

$userid = $vbulletin->userinfo['userid'];
$sql2 = "SELECT *
FROM `dbtech_status_statuslog`
ORDER BY `dbtech_status_statuslog`.`statuslogid` DESC
LIMIT 1";               

$query = mysql_query($sql2);

if(!$query)
{
echo 'Query failed';
}
else
{
echo 'Query Ok';
}

$data = mysql_fetch_assoc($query);

$template_hook['status'] = $data['status'];
echo $template_hook['status'];


kh99 01-22-2012 04:04 PM

Just for an experiment, try decreasing the execution order of your plugin. Or else try using hook parse_templates instead.

Mark.B 01-23-2012 07:53 PM

Thanks, that was it...needs to be parse_templates. never quite understand why that has to be the case, since I guess that's not what that hook was designed for.

kh99 01-23-2012 08:17 PM

I don't know - I think the hooks are named more for where they are in the code than what you're 'supposed' to do with them (although sometimes it's the same thing). parse_templates is just before the header is rendered (as well as some other common templates) so I think it's a good place to register extra variables.


All times are GMT. The time now is 10:54 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.01408 seconds
  • Memory Usage 1,710KB
  • 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
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)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