Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-16-2012, 10:54 AM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 05-16-2012, 11:45 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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}.
Reply With Quote
  #3  
Old 05-16-2012, 12:26 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 05-16-2012, 12:45 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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).
Reply With Quote
  #5  
Old 05-16-2012, 04:04 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 05-16-2012, 07:59 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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));
Reply With Quote
  #7  
Old 05-17-2012, 12:10 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 05-17-2012, 01:28 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 05-17-2012, 04:59 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:42 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.04977 seconds
  • Memory Usage 2,242KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete