PDA

View Full Version : Finding the right hook for adding text to the header template in CMS


MrEyes
09-09-2010, 08:16 PM
I have a mini mod on my site that looks something like this:

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:


<?
$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:


<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.