vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Insert template within template (https://vborg.vbsupport.ru/showthread.php?t=243330)

deadbydawn 05-26-2010 03:10 PM

Insert template within template
 
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.

PHP Code:

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

Code:

{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:
PHP Code:

$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


All times are GMT. The time now is 08:41 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01097 seconds
  • Memory Usage 1,719KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete