vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   looking for tutorial that explains how to show variable to different templates (https://vborg.vbsupport.ru/showthread.php?t=268186)

radiofranky 08-08-2011 08:26 PM

looking for tutorial that explains how to show variable to different templates
 
Hi,
I was wondering if there is something that explains how to show variables in not registered templates?

for example,

Variable X is registered in xyz template. How to modify it to show variable X in abc template.
how to show total threads in HEADER template?

thanks

kh99 08-09-2011 01:53 PM

Quote:

Originally Posted by radiofranky (Post 2231025)
how to show total threads in HEADER template?

The variable $totalthreads is registered in the FORUMHOME template to show that value. But registering that variable in the header template won't work because the value is only calculated in the forum.php script, so if you are on any other page it will be blank. The only way to do it would be to create a plugin that calculates the value, and use a hook that will calculate it on every page.

Edit: Your plugin code could be something like (and parse_templates is probably a good hook to use):

PHP Code:

$tt $vbulletin->db->query_first("SELECT SUM(threadcount) AS totalthreads FROM " TABLE_PREFIX "forum");
$total $tt['totalthreads'];

vB_Template::preRegister('header', array('totalthreads' => $total));  

unset(
$tt$total); 


and then put {vb:raw totalthreads} in header template where you want it.

This adds a query to every page, and it's always good to reduce the number of queries to speed up your site, but it's probably not a big deal. You could cache the value in the datastore, but that's a more advanced topic.

Artashes 09-01-2011 09:03 PM

is there a benefit of unsetting the $tt variable at the end? First time I've seen it used in this context…

kh99 09-01-2011 09:27 PM

Quote:

Originally Posted by Artashes (Post 2240973)
is there a benefit of unsetting the $tt variable at the end? First time I've seen it used in this context?

Probably not much, I guess I was feeling kind of "careful" when I wrote that. It's possible that other code executed after this could use $tt or $total and expect it to be unset to start with.

Lynne 09-01-2011 11:12 PM

Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide


All times are GMT. The time now is 06:57 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.01051 seconds
  • Memory Usage 1,724KB
  • 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_php_printable
  • (2)bbcode_quote_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