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 Into Existing Template (https://vborg.vbsupport.ru/showthread.php?t=283005)

Rich 05-16-2012 09:54 AM

Insert Template Into Existing Template
 
I am so frustrated with the template system. I loved the days when $variable was used. I am completely lost on this new way of inserting templates into existing templates. I have read the article on variables and don't seem to be understanding it because it doesn't seem to be working for me.

All I want to do is add my ad code to the top of the forumdispaly template via calling another template.

Lets say the template were called "myadtemplate". How the heck do I get it to show at the top of the forumdisplay template below the navbar? I simply can't get it to display. I am trying to do this via plugins. I had no issues in the past when I could simply set the variable as $variable and eval the template.

Thanks for any help you can offer.

kh99 05-16-2012 10:45 AM

Plugin using hook location forumdisplay_complete:

Code:

$templater = vB_Template::create('myadtemplate');
$myadtemplate = $templater->render();
vB_Template::preRegister('FORUMDISPLAY', array('myadtemplate' => $myadtemplate));


Then edit your forumdisplay template and insert {vb:raw myadtemplate}.

Rich 05-16-2012 11:26 AM

I appreciate the help kh99 but I attempted to use that code with no luck. I had used various deviations of that same code when I tried before as well.

kh99 05-16-2012 11:45 AM

You're right, it doesn't work - the template name FORUMDISPLAY should be in all caps. I fixed the code above (which now seems to work for me).

Rich 05-16-2012 03:04 PM

Thank you again. I can't believe I played with it for as long as I did and the entire time it was capitalization causing me problems. At least i had the code right at some point, lol.

That code works as expected but I am not certain I can actually use it now. lol It called my template as expected but when I added my conditionals based on forumid I didn't get any output. The conditional works fine within the forumdisplay template itself so I am guessing I need to either alter the condition since it is called from another template or I need to append the plugin to another hook.

This is the conditional:

Code:

<vb:if condition="in_array($foruminfo['forumid'], array(12,13,14,15,16,17,22))">
Ad Code Here
</vb:if>

That works great in the forumdisplay tem[plate but ceases to work when it is called via the custom template. since I have blocks of ads being called based on foum ids I wanted to call them outside the forumdisplay template because of how large the template will be. If it isn't one thing, its another! lol

kh99 05-16-2012 06:59 PM

You need to register $foruminfo for use in your custom template, like this:

Code:

$templater = vB_Template::create('myadtemplate');
$templater->register('foruminfo', $foruminfo);
$myadtemplate = $templater->render();
vB_Template::preRegister('FORUMDISPLAY', array('myadtemplate' => $myadtemplate));


Rich 05-17-2012 11:10 AM

Thanks kevin but that returns the following error.

Fatal error: Call to a member function register() on a non-object in /home/site/public_html/forumdisplay.php(1198) : eval()'d code on line 51

This is the exact plugin code I am using:

Code:

$templater = vB_Template::create('custom_forumsponsorads');
$templater->register('foruminfo', $foruminfo);
$forumsponsorads = $templater->render();
vB_Template::preRegister('FORUMDISPLAY', array('forumsponsorads' => $forumsponsorads));

It is being executed at the forumdusplay_complete hook.

I am really starting to dislike how they changed things with vB.

kh99 05-17-2012 12:28 PM

Hmm...I don't see why you'd get that error. When I first posted the code I had a typo in it where that register line had $template instead of $templater, but I fixed it and the code you posted doesn't have that. Is it possible you used my code before it was fixed (because you probably got emailed the original version)? I tried what you posted above and it doesn't give an error even though I don't even have that template.

I know what you mean, I've been a programmer pretty much my entire life and I found it frustrating at first. It makes a lot of sense after a while, but unfortunately that doesn't help people who just want to get something done.

Rich 05-17-2012 03:59 PM

It does appear that I may have run it with the unedited version. I copy and pasted the code you wrote and just swapped the myadtemplate with my actual stuff since thats all I did the first time. It is up and running. Thank you very much.


All times are GMT. The time now is 02:30 AM.

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.02726 seconds
  • Memory Usage 1,727KB
  • 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
  • (4)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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