View Full Version : Displaying a template within the header template?

01 Dec 2009, 22:28
I've made a very simple template (called tmplt_simpleWord) which is just a single word: test
I want to display this template in the header.

In the header template, I've got:
{vb:raw show_simpleWord}

The plug-in is:
$templater = vB_Template::create('tmplt_simpleWord');
$templateValues['show_simpleWord'] = $templater->render();
vB_Template::preRegister('header', $templateValues);

I've tried this with the following hooks but none of them does anything to the header:

I've been successful in inserting the same template into FORUMHOME by switching the last line of the plugin from:
vB_Template::preRegister('header', $templateValues);

vB_Template::preRegister('FORUMHOME', $templateValues);

, setting the hook to forumhome_start and adding the same template code to the FORUMHOME template.

What am I doing wrong in trying to insert the template into the header?
Any help appreciated.


01 Dec 2009, 23:00
I was just replying to someone wanting to do something similar in the footer template. The header template, just like the footer and headinclude template, gets rendered early on (check class_bootstrap.php). You will have to pick a hook location that is rendered before the template is rendered, or rerender it.

01 Dec 2009, 23:39
Thanks for that Lynne, I tried using global_start which I thought would precede everything else but no luck. However (as Seven Skins has said in the thread you mentioned) I too can output values directly from the plug-in, but I can't seem to insert a template.

So where as this works:

Hook: global_start

$simpleWord = "word";
vB_Template::preRegister('header',array('show_simpleWord' => $simpleWord));

This doesn't:

Hook: global_start

$templater = vB_Template::create('tmplt_simpleWord');
$templateValues['show_simpleWord'] = $templater->render();
vB_Template::preRegister('header', $templateValues);

Please consider this thread closed as I will be following Seven Skins' thread (http://www.vbulletin.org/forum/showthread.php?t=229281) for a solution instead.

01 Dec 2009, 23:56
Try something more like this:
$templater = vB_Template::create('tmplt_simpleWord');
$templateValues = $templater->render();
vB_Template::preRegister('header', array('templateValues' => $templateValues));

And then use {vb:raw templateValues} in the template.

Did you look in the file I told you to? You'll see the hook location parse_templates right above where the templates are rendered. Why not try that hook location?

02 Dec 2009, 09:41
Gah, I totally missed that sorry. And thanks - changing the hook to parse_templates with the original code works perfectly :)

Thanks again.