![]() |
|
Thread Tools |
#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:
The first line of ForumbitLev2 uses the forum ID:
So I tried using that in InsideListing, but no output. Here are some samples of what I tried using in the InsideListing template: Nothing displayed with any of these:
Values were displayed for these:
----------------------------------------- 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:
Here's the contents of forum_id_hook_forumbit_display.php:
I tried the following in my InsideListing template:
Only the word "TEST" appeared next to each forum name. Any thoughts? No members have liked this post.
|
#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:
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: http://www.vbulletin.org/forum/showthread.php?t=228078 No members have liked this post.
|
#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:
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:
At the end of the forum.php code, the ad_location and forumbits template arrays (among others) are registered for use within the FORUMHOME template and the page is rendered. -------------------------------------------------------------- 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.
I tested it using the following as the contents of the ad_board_inside_forum_listing template:
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 No members have liked this post.
|
#4
|
||||
|
||||
I would think this code (copied from above) using the forumbit_display hook should work:
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? No members have liked this post.
Last edited by kh99; 08 Jun 2012 at 21:17. Reason: fixed "this this" |
#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 08 Jun 2012 at 20:44 --------------- One more time. Here is my plugin code:
Here is the code in the file called by the plugin:
Here is the code in my template named "ad_board_inside_forum_listing":
Here's the code I place in "forumhome_forumbit_level2_post" and the other forumbit files:
Case A: 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 No members have liked this post.
Last edited by codewaggle; 08 Jun 2012 at 20:52. |
#6
|
|||
|
|||
Originally Posted by joe-marinas
That's OK then, you can use $forum. Sorry I added to the confusion.![]()
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). No members have liked this post.
|
#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 No members have liked this post.
Last edited by codewaggle; 08 Jun 2012 at 23:26. Reason: Update and add question |
#8
|
|||
|
|||
Glad you got it figured out.
Originally Posted by joe-marinas
![]()
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. The following members like this post: 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:
Then in the forumbit templates I used:
Be Well No members have liked this post.
Last edited by codewaggle; 10 Jun 2012 at 17:03. |
#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. No members have liked this post.
Last edited by kh99; 10 Jun 2012 at 13:27. |
#11
|
|||
|
|||
Originally Posted by kh99
![]()
Originally Posted by kh99
In your previous post, you kind of mentioned register_globals(). You pointed out that certain variables are registered automatically and where in the code it happens. The variables you pointed out are registered in the register_globals() function. Within that function the register_global() (no "s") function is called:![]()
$this->register_global('vbphrase'); $this->register_global('vbcollapse'); I was using the register_global() (no "s") function incorrectly. I was thinking it made a reference to the variable available globally, but as you point out, that's what $GLOBALS does anyway. Thanks again for the help ------------------------------------------- For anyone reading this after us: register_globals() is called with the purpose of registering certain variables within the scope of the particular template being rendered (they are already in the $GLOBALS array). Basically, it does a $templater->register(), but it passes the global variable by reference so that it will have the latest value when used rather than the value it held when it was registered. The final result is: $templater->registered['vbphrase'] =& $GLOBALS['vbphrase']; In the end, the difference between using register_globals() and not is the way you reference a variable within the template as it's being rendered. Using register_globals(): {vb:raw vbphrase.monday} Not using register_globals(): {vb:raw GLOBALS.vbphrase.monday} Be Well No members have liked this post.
|
#12
|
|||
|
|||
Ah, I see - that does make sense. And it probably is good for readability, if nothing else, to explicitly register the variables you use.
No members have liked this post.
|
![]() |
«
Previous Thread
|
Next Thread
»
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
|
|
New To Site? | Need Help? |
All times are GMT. The time now is 01:54.