PDA

View Full Version : Insert template within template


deadbydawn
05-26-2010, 03:10 PM
Is it possible for me to call a template from inside another template?

eg, I'd like to throw all of my custom stuff into a brand new template, and then open the SHOWTHREAD template and manually place it in there without junking it up too much.

Is it only possible to do this via plugin/template_hook calls, or is there a manual method i'm missing?

consolegaming
05-27-2010, 10:59 AM
Yes it's possible, I do this with my header and footer and then just have one liners in the two templates. First of all you need to create a plugin. The parse_templates hook works well for me.

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

And then inside the footer template (in the example above as that's where I registered the custom template) you just do:

{vb:raw custom_template}

Basically you need to register your custom template as a variable which you can then use in the template you just registered it for.

deadbydawn
05-27-2010, 03:59 PM
Fantastic, thank you so much!

I'm playing with it a bit now and i'm getting it to insert the template as I would expect, but there's one thing I'm not certain about.. Because I am doing something with the SHOWTHREAD template, I am making use of some variables such as {vb:raw threadid} and {vb:raw pagenumber}.

These are not being called properly when using the plugin method of inserting the template.. is that simply a byproduct of this (meaning I should likely continue to edit the template manually), or is there a method that would make it work?

I thought perhaps changing the hook call could allow it to have the necessary info first, but I don't think that's it. Maybe there's a way for me to tell it to get that info from showthread?

Thanks again

consolegaming
05-28-2010, 12:20 AM
I'm guessing your problem is that you need to register these variables for use in your custom template.

Just after the first line (before the render line) try this in your plugin:
$templater->register('threadid', $threadid);

That's telling it to register the threadid variable to be used inside your custom template. It's a bit of a pain in the backside having to register already existing variables I know but that should be what you need. I know when I first looked at the system I just expected these variables to work straight away lol.

deadbydawn
05-28-2010, 04:47 PM
That was exactly it. You are awesome, thank you! :D