PDA

View Full Version : Rendering Custom Template


Seven Skins
01 Dec 2009, 21:20
I have tried following this: http://www.vbulletin.org/forum/showthread.php?t=228078 but no luck with what I am trying to do.
Most probably it will be simple solution but I can not get it to work. (I am new to writing plugins etc ...)

What I am trying to do is:

I have template name "TEST" with just simple HTML code <div>Some text</div>

And I just want this HTML to be inserted into e.g. footer template.

I have tried this in global_start plugin.

$templater = vB_Template::create('TEST');
$test = $templater ->render();
vB_Template::preRegister('footer',array('test' => $test));

or

$templater = vB_Template::create('TEST');
$templatevalues['test'] = $templater->render();
vB_Template::preRegister('footer', $test);

And this in footer template.

{vb:raw test}


But that template does not show in footer template.


Thanks

.

Lynne
01 Dec 2009, 21:33
If you are creating a whole different footer template, then I would call it something else. The footer template gets rendering by the vbulletin engine very early on, and if you are using the same name, then you may get weird results.

Seven Skins
01 Dec 2009, 21:47
No, I just want to add something to footer template ... but need separate template for it, as this template will be edited frequently. I am working on a simple product which I will release here if successful :)

.

Lynne
01 Dec 2009, 21:57
Ah, now I see what you are doing. I wasn't reading it correctly. The first code that you posted looks correct. However, what hook location are you using? As I said before, the footer template gets rendered at the very beginning (in the global.php file) and you may to render it again in order to get your stuff added.

Lynne
01 Dec 2009, 22:07
Ah, now I see what you are doing. I wasn't reading it correctly. The first code that you posted looks correct. However, what hook location are you using? As I said before, the footer template gets rendered at the very beginning (in the global.php file) and you may to render it again in order to get your stuff added.

Seven Skins
01 Dec 2009, 22:17
I have used global_start hook location.

This seems to add the data to footer with the above hook.

$test = "Some text here";
vB_Template::preRegister('footer',array('test' => $test));

But I need to add/render the template.

.

--------------- Added 1259711598 at 1259711598 ---------------

I have searched "class_bootstrap.php" and found that "parse_templates" was called just before header and footer templates got rendered.

"parse_templates" hook seems to work.

.

Lynne
01 Dec 2009, 22:58
So let's see the code you are trying to use to render the template and then preregister it. And, look up where the footer template is rendered... the parse_templates hook is right above there. Have you tried it?

Seven Skins
01 Dec 2009, 23:04
Yup, its working (As replied above) :)

Here is the code I used in "parse_templates" hook:

$templater = vB_Template::create('TEST');
$templatevalues['test'] = $templater->render();
vB_Template::preRegister('footer', $templatevalues);
vB_Template::preRegister('header', $templatevalues);

And this in footer or/and header template:
{vb:raw test}


Thanks

.

RagingPenguin
27 Apr 2011, 17:02
How would one go about doing this in a way that would make a custom template available in all other templates, and not have to preRegister each of them?

Here's what I have so far.

cache_templates
$cache = array_merge($cache, array(
'layout_a',
'layout_b',
'layout_c',
'layout_d'
));

parse_templates
global $layout_a, $layout_b, $layout_c, $layout_d;
$layout_a = vB_Template::create('layout_a')->render();
$layout_b = vB_Template::create('layout_b')->render();
$layout_c = vB_Template::create('layout_c')->render();
$layout_d = vB_Template::create('layout_d')->render();
}

But I think it should be more like:

parse_templates
global $layout_a, $layout_b, $layout_c, $layout_d;
$layout_a = vB_Template::create('layout_a')->render();
$layout_b = vB_Template::create('layout_b')->render();
$layout_c = vB_Template::create('layout_c')->render();
$layout_d = vB_Template::create('layout_d')->render();

// for each cached template, global or otherwise, register
// the above templates as variables
foreach ($globaltemplates as $key => $value)
{
vB_Template::preRegister($key, array(
'layout_a' => $layout_a,
'layout_b' => $layout_b,
'layout_c' => $layout_c,
'layout_d' => $layout_d
));


I know it doesn't work, but that's because I'm not sure what array to use/globalize here.

Help?