vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Adding a site-wide template variable. (https://vborg.vbsupport.ru/showthread.php?t=252018)

neverstop 10-13-2010 12:17 AM

Adding a site-wide template variable.
 
Hi,

I am looking to add a template variable that will be usable in all templates. The variable will be an integer between 1-9 that will be random on each page load. I want to use this for site wide "advert page-skinning" for lack of a better term.

Basically i want to be able to add something like this to any template:

Code:

<vb:if condition="$integer == 3">fu</vb:if>

or

<vb:if condition="$integer > 5">fu</vb:if>

or

<vb:if condition="in_array($integer, array(4,8,9))">fu</vb:if>

Something like this should be fairly simple via a plugin no?

Thanks in advance.

Lynne 10-13-2010 03:44 AM

Used in *all* templates? So, in the header, and the footer, and the SHOWTHREAD, and ..... In vB4, you need to preregister variables for use in templates, so this may be problematic. You may try piggy-backing on the $bbuserinfo array, but I have no idea if that would work or not.

neverstop 10-13-2010 03:57 AM

What got me thinking was that THIS_SCRIPT can be used in all templates cant it? of course I could be wrong

Lynne 10-13-2010 01:58 PM

Yes. There are some variables that do not need to be registered like the $bbuserinfo variable I mentioned (along with $session and $vboptions, and I can't remember them all).

neverstop 10-21-2010 01:55 AM

I will post my solution for posterity's sake.

I wasnt able to use a variable for all templates but registering vars for templates is pretty easy.

I added a plugin to the "parse_templates" hook location:

PHP Code:

$ad_int mt_rand(110);
vB_Template::preRegister('header',array('ad_int' => $ad_int));
vB_Template::preRegister('navbar',array('ad_int' => $ad_int));
vB_Template::preRegister('adv_portal_cube_banner',array('ad_int' => $ad_int));
vB_Template::preRegister('postbit_legacy',array('ad_int' => $ad_int)); 

mt_rand() is a built in RNG and in this case 1 is the minimum, and 10 is the maximum.

I am not sure if this is the proper way to do this but it is working for me, I can use {vb:raw ad_int} in the specified templates. Maybe someone can chime in if there is a better way to do it.

Cheers


All times are GMT. The time now is 10:37 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.02060 seconds
  • Memory Usage 1,721KB
  • 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)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