vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Finding the right hook for adding text to the header template in CMS (https://vborg.vbsupport.ru/showthread.php?t=250226)

MrEyes 09-09-2010 08:16 PM

Finding the right hook for adding text to the header template in CMS
 
I have a mini mod on my site that looks something like this:

Code:

Hook Location : global_start
Execution Order : 5
PHP Code : require_once('./includes/_taglinemessages.php');

The code for the included PHP file looks something like this:

Code:

<?
$taglines = array();
$taglines[] = 'Text 1';
$taglines[] = 'Text 2';
$taglines[] = 'Text 3';

$rand_keys = array_rand($taglines, 1);
$template_hook['tagline'] = $taglines[$rand_keys];
?>

Then in my header template I have the following:

Code:

<span>Message : <i>{vb:raw template_hook.tagline}</i></span>
Now, all this works perfectly and on each refresh I see a random selection from the $taglines array displayed at the top of the page. However it doesn't work on any CMS page. So either I am using the wrong hook of the template_hook variable isn't part of the cms templater code.

So, does anybody have any ideas on how to solve this?

MrEyes 09-11-2010 09:23 AM

Anybody?

Lynne 09-11-2010 02:27 PM

First, don't use global_start, it's deprecated (do a search on it in your files and you'll see). I'd actually suggest global_bootstrap_init_complete otherwise you'll need to preregister template_hook (again, you'll see this if you look at the code).

I put the php directly into the plugin and it worked fine for me. Did you try that?

MrEyes 09-11-2010 07:00 PM

Fantastic, the hook suggested worked a treat.

Regarding the location of the php code, I prefer to put hook php into file. Doing it this way means that the opcode cachers can work on the file - if the php is in the hook itself then it can't be cached in the same way. For a couple of hooks here and there it makes little difference, but once you have a number of hooks the difference is noticeable.


All times are GMT. The time now is 01:21 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.01074 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
  • (3)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