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 09-01-2011, 08:58 PM
greytone greytone is offline
 
Join Date: Jul 2010
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to print Forum ID?

How do I put the forumid dynamically into a template.

I have tried {vb:raw foruminfo.forumid} but it doesn't work. It just prints nothing.

I've read about registering variables before using them, but I can't figure out where to register a variable so that it is accessible. (I'm working in the "header" template.)

Many thanks!
Reply With Quote
  #2  
Old 09-02-2011, 12:55 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can create a plugin using hook parse_templates, and pre-register a variable to the header template, like:

Code:
vB_Template::preRegister('header', array('forumid' => $forumid));

and then in the header template:

Code:
{vb:raw forumid}

However, finding the forumid might be a bit of a problem since not every page is going to have $foruminfo defined. You could try this:

Code:
global $foruminfo;
$forumid = $foruminfo['forumid'];
vB_Template::preRegister('header', array('forumid' => $forumid));

(or you could of course just register $foruminfo and use foruminfo.forumid like in your example), but I think you'll find that it only shows a forum id on certain pages, if at all.
Reply With Quote
  #3  
Old 09-02-2011, 09:53 PM
greytone greytone is offline
 
Join Date: Jul 2010
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Kevin,

I understand the principle that you're suggesting, but I have no idea where to put the first or third code snippets that you provided. I know where to put the vb:raw code from your second code snippet because I can see other such code in the header template.

PHP doesn't appear to be parsed in the header template, so I'm guessing that it shouldn't be there.

Sorry if this is obvious!

Many thanks,
-Adam
Reply With Quote
  #4  
Old 09-02-2011, 10:33 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No problem. You want to create a plugin. You can do that by going to "Add New Plugin" under "Plugins & Products" in the admin control panel. Select the hook location (parse_templates) from the drop down menu, and enter a title (something so you can remember what it's for later). Put the code in the big text box, select the "Yes" radio button, and press "Save".

The code you enter will be included at a certain point in the vb code. In this case, if you're interested, you can look at includes/class_bootstrap.php and search for parse_templates and you'll find this:
PHP Code:
($hook vBulletinHook::fetch_hook('parse_templates')) ? eval($hook) : false

That line will get any code you entered for that hook location and execute it.

Sorry if that's TMI, you can ignore everything after the first paragraph.
Reply With Quote
  #5  
Old 09-06-2011, 03:38 PM
greytone greytone is offline
 
Join Date: Jul 2010
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default


Everything is working now.
Reply With Quote
  #6  
Old 09-06-2011, 03:45 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Did you try just using $GLOBALS[forumid]? {vb:raw GLOBALS.forumid}
Reply With Quote
  #7  
Old 09-06-2011, 10:31 PM
ltwinnerr ltwinnerr is offline
 
Join Date: Feb 2010
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ive seen a good few people saying to use 'preRegister' when dealing with templates in general.

Why can't you just just the standard $templater->register('xyz', $xyz);?

Or do they both do exactly the same thing?
Reply With Quote
  #8  
Old 09-06-2011, 10:41 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ltwinnerr View Post
Why can't you just just the standard $templater->register('xyz', $xyz);?
You can, but you need the $templater that gets set when you create the template object. For templates that are created and rendered in the vb code, there's no hook location between the create() and the render() calls so there's no way to register a new variable using register().
Reply With Quote
  #9  
Old 06-15-2014, 11:58 AM
behcet behcet is offline
 
Join Date: Apr 2007
Posts: 37
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

can i use {vb:raw GLOBALS.title} ?
Reply With Quote
  #10  
Old 06-15-2014, 12:34 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by behcet View Post
can i use {vb:raw GLOBALS.title} ?
Lynne was right of course the OP could just have used the global. But I don't know if there's a global for forum title. Which template do you want to use it in?
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 08:17 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.04607 seconds
  • Memory Usage 2,253KB
  • 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
  • (3)bbcode_code
  • (1)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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