The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
forumbit Template - How to Get Forum ID For Use In Included Template?
Hi,
I created a product based on the existing Advertising functionality. I added a slot next to each forum name on the forum.php page. I'm able to display an image next to each forum name, but I'd like to show different images for different forum ID's. --------------------------------- I created a template called board_inside_forum_listing (InsideListing). InsideListing is loaded into the forumhome_forumbit_level2_post (ForumbitLev2) template. like this: Code:
{vb:raw ad_location.board_inside_forum_listing} The first line of ForumbitLev2 uses the forum ID: Code:
{vb:raw forum.forumid} Nothing displayed with any of these: Code:
{vb:raw forum.forumid} {vb:var forum.forumid} <vb:if condition="$vbulletin->GPC['forumid'] == 10"> Has Value </vb:if> <vb:if condition="$vbulletin->GPC['forumid']"> Has Value </vb:if> {vb:var global} {vb:var templater->forumid} Values were displayed for these: Code:
<img src="images/forum_logos/forum_10.png"> Plain Text {vb:var vbulletin->forumcache['10']['forumid']} // displayed "10" next to each forum name ----------------------------------------- I've also tried creating a plugin using the the forumbit_display hook. Seemed like a good location because the code for each forum is rendered just after that. Here's my plugin code: Code:
ob_start(); require_once('includes/forum_id_hook_forumbit_display.php'); $marbuzz_forumbit_display_hook = ob_get_contents(); ob_end_clean(); vB_Template::preRegister('ad_board_inside_forum_listing',array('marbuzz_forumbit_display_hook' => $marbuzz_forumbit_display_hook)); Here's the contents of forum_id_hook_forumbit_display.php: Code:
$marbuzz_forumbit_display_hook['forum_id'] = $forumid; return $marbuzz_forumbit_display_hook; I tried the following in my InsideListing template: Code:
<vb:if condition="$marbuzz_forumbit_display_hook['forum_id']"> Has Value </vb:if> {vb:var marbuzz_forumbit_display_hook.forum_id} {vb:raw marbuzz_forumbit_display_hook.forum_id} TEST Any thoughts? |
#2
|
|||
|
|||
In your board_inside_forum_listing template, you can only use variables that have been registered to it (or certain variables that are registered automatically). You don't show the code where you rendered your template, but I assume somewhere you have something like:
Code:
$template = vB_Template::create('board_inside_forum_listing'); $template->register('forumid', $forumid); $template->render(); // of course you'd assign the result of this to something... you'd want to add a register line in the middle to register the forumid (I'm not sure if $forumid would be the right variable - it depends where you're registering it). Then in board_inside_forum_listing you could use {vb:raw forumid}, or $forumid in a condition. The second example you show might have worked, but the ob_start()/ob_end_clean() thing captures the output of any code that's between it, and yours didn't output anything. But that code is from an example of how to include an external php file that outputs some html (for instance), so that isn't what you want to use for your siutuation. If you haven't seen this article yet, it might help: https://vborg.vbsupport.ru/showthread.php?t=228078 |
#3
|
|||
|
|||
Thanks for your assistance,
I forgot to include the full info about my board_inside_forum_listing template. I used the native Advertising functionality as a starting point, I copied and modified these files: /admincp/ad.php => /admincp/marbuzz_insert_block.php /includes/functions_ad.php => /includes/functions_marbuzz_insert_block.php /includes/xml/ad_locations_vbulletin.xml => /includes/xml/block_locations_marbuzz_insert_block.xml I basically just changed the db table references (I copied the tables used by the Ad functionality) and the names of the templates that are loaded to display the bloack of code. So on the forum.php page, Ads uses these templates: board_after_forums and board_below_whats_going_on, I'm using board_inside_forum_listing. I created a plugin (marbuzz_forumhome_start_hook.php) that uses the forumhome_start hook (I can't use the forumhome_complete hook, because it occurs after $forumbits is constructed), that's where I render the template, the plugin code is: Code:
array_push($globaltemplates, 'ad_board_inside_forum_listing'); $ad_location['board_inside_forum_listing'] = vB_Template::create('ad_board_inside_forum_listing')->render(); When that template is rendered, I don't want to key on the variable I need (forum ID), because the forum ID isn't available then. When forum.php is rendered, the construct_forum_bit function is run near the end, it creates each forum entry that's displayed. construct_forum_bit() uses the forumhome_forumbit_level2_post template to create forum entries for display (there are a few templates used depending on forum level and posts). My ad_board_inside_forum_listing template is loaded inside the forumhome_forumbit_level2_post template, I need to key on the ID of the forum whose entry is being created. So I'd like the ad_board_inside_forum_listing template to contain a reference to the forum ID, like this: Code:
<vb:if condition="$forumid == 10"> //10 stands for the forum ID, it would vary depending on which forum row the image should appear in. Display Image </vb:if> -------------------------------------------------------------- I just tried a different approach, I used the forumbit_display hook near the end of the construct_forum_bit function. I registered the forumid variable as you suggested and used the $forum array that is registered when each forum entry is created. Code:
$template = vB_Template::create('ad_board_inside_forum_listing'); $template->register('forumid', $forumid); $forum['board_inside_forum_listing'] = $template->render(); Code:
{vb:var forumid} {vb:raw forumid} <vb:if condition="$forumid == 25">Show this if forum id is 25</vb:if> It worked somewhat, I can access the current forumid, but it's only displayed in the row for the first forum listing. I'm trying to render the ad_board_inside_forum_listing template once for each forum in the loop, can templates be rendered multiple times or only once (explaining the single output in this test)? Be Well |
#4
|
|||
|
|||
I would think this code (copied from above) using the forumbit_display hook should work:
Code:
$template = vB_Template::create('ad_board_inside_forum_listing'); $template->register('forumid', $forumid); $forum['board_inside_forum_listing'] = $template->render(); but I assume that 3rd line should be $ad_location['board_inside_forum_listing']. Yes, you can render a template more than once, so it should work. I don't see offhand why it's only displaying in the first line. Are you seeing the 2 forum id numbers from the first two lines in your template? Are you sure they're all using the level2 forumbit template? |
#5
|
|||
|
|||
The first forum was ID 25, so all three lines in my template worked, I saw:
25 25 Show this if forum id is 25 I added the include to all four forumbit templates: forumhome_forumbit_level2_post forumhome_forumbit_level2_nopost forumhome_forumbit_level1_post forumhome_forumbit_level1_nopost But the output only appeared next to the first forum listing. For the include, I used the ad_location array when using the hook on forum.php because it was registered there: $ad_location['board_inside_forum_listing'] I used the forum array when I used the forumbit_display hook because the forum array was being registered there: $forum['board_inside_forum_listing'] I'll try using the ad_location array while using the forumbit_display hook and check through my code for mistakes. Be Well --------------- Added [DATE]1339184649[/DATE] at [TIME]1339184649[/TIME] --------------- One more time. Here is my plugin code: Code:
ob_start(); require_once('includes/plugin_marbuzz_insert_block_hook_forumhome_start.php'); $marbuzz_insert_block_forumhome_start = ob_get_contents(); ob_end_clean(); vB_Template::preRegister('ad_board_inside_forum_listing',array('marbuzz_insert_b Code:
array_push($globaltemplates, 'ad_board_inside_forum_listing'); $template = vB_Template::create('ad_board_inside_forum_listing'); $template->register('forumid', $forumid); $ad_location['board_inside_forum_listing'] = $template->render(); OR $forum['board_inside_forum_listing'] = $template->render(); print $forumid; echo $forumid; Code:
test {vb:var forumid} {vb:raw forumid} <vb:if condition="$forumid == 25">Show this if forum id is 25</vb:if> {vb:var marbuzz_forumbit_display_hook} {vb:raw marbuzz_forumbit_display_hook} <vb:if condition="$marbuzz_forumbit_display_hook== 25">Show this if forum id is 25</vb:if> Code:
{vb:raw ad_location.board_inside_forum_listing} OR {vb:raw forum.board_inside_forum_listing} Use the forumhome_start hook and the $ad_location variable. The text appears next to each forum name, no ID. Case B: Use the forumbit_display hook and the $ad_location variable. Nothing appears. Case C: Use the forumbit_display hook and the $forum variable. THe Text and ID appears next to the name of the first forum only. I tried echoing and printing the ID and then using the plugin variable "marbuzz_insert_block_forumhome_start" to display it, but nothing there. Any idea why it doesn't work past the first forum? Be Well |
#6
|
|||
|
|||
Quote:
I still don't see why it would appear only once. Maybe I'll try some of it and if I figure out anything I'll let you know (or maybe someone else will see the problem). |
#7
|
|||
|
|||
Got It!
I used require_once() when I created the plugin. I changed it to require() and it displays next to all of the forums. Now I need to figure out how to store and process multiple versions of the ad_board_inside_forum_listing template so I can display different images next to different forums. Edit: This is already done in the ad code, I just need to add my own criteria for the forum home listings. In your first post, you said: Is there a list of the variables that are registered automatically? Thanks for your help, it gave me a better understanding of how things work. Be Well |
#8
|
|||
|
|||
Glad you got it figured out.
Quote:
From includes/class_core.php, around line 4568, these variable are registered for you: $vbulletin->userinfo (as 'bbuserinfo') $vbulletin->options (as 'vboptions') $vbulletin->session->vars (as 'session') $vbphrase $vbcollapse $ad_location $style $show $template_hook There are a few other special cases, but you probably don't care about those. |
Благодарность от: | ||
codewaggle |
#9
|
|||
|
|||
Your pointer to the register_globals() function came in handy. I used what I learned to register my template globally for use in all four "forumhome_forumbit_levelx_xxx" templates.
I used this in the file called by my plugin: Code:
$template = vB_Template::create('ad_board_inside_forum_listing'); $template->register('forumid', $forumid); $cw_forumbit_global_with_id['board_inside_forum_listing'] = $template->render(); $GLOBALS[cw_forumbit_global_with_id] = $cw_forumbit_global_with_id; UPDATE: (Thanks to kh99 for his guidance.) The following line isn't needed and was used incorrectly: $template->register_global('cw_forumbit_global_with_id'); Then in the forumbit templates I used: Code:
{vb:raw GLOBALS.cw_forumbit_global_with_id.board_inside_forum_listing} Be Well |
#10
|
|||
|
|||
I didn't mention register_globals() - I don't think that's something you normally want to call directly.
GLOBALS.name seems to work to access a global even if you don't registered it. So I suppose you could say that $GLOBALS[] is also "registered" by default. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|