PDA

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


saajjj
12-01-2009, 08:28 PM
Hello,
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:
global_start
process_templates_complete

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);

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

Cheers,

Lynne
12-01-2009, 09:00 PM
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.

saajjj
12-01-2009, 09:39 PM
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_simp leWord' => $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 (https://vborg.vbsupport.ru/showthread.php?t=229281) for a solution instead.

Lynne
12-01-2009, 09:56 PM
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?

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

Thanks again.