PDA

View Full Version : How to print Forum ID?


greytone
09-01-2011, 08:58 PM
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!

kh99
09-02-2011, 12:55 PM
You can create a plugin using hook parse_templates, and pre-register a variable to the header template, like:

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


and then in the header template:

{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:


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.

greytone
09-02-2011, 09:53 PM
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

kh99
09-02-2011, 10:33 PM
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:
($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.

greytone
09-06-2011, 03:38 PM
:D
Everything is working now.

Lynne
09-06-2011, 03:45 PM
Did you try just using $GLOBALS[forumid]? {vb:raw GLOBALS.forumid}

ltwinnerr
09-06-2011, 10:31 PM
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?

kh99
09-06-2011, 10:41 PM
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().

behcet
06-15-2014, 11:58 AM
can i use {vb:raw GLOBALS.title} ?

kh99
06-15-2014, 12:34 PM
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?