The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
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! |
#2
|
|||
|
|||
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. |
#3
|
|||
|
|||
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 |
#4
|
|||
|
|||
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:
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. |
#5
|
|||
|
|||
Everything is working now. |
#6
|
||||
|
||||
Did you try just using $GLOBALS[forumid]? {vb:raw GLOBALS.forumid}
|
#7
|
|||
|
|||
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? |
#8
|
|||
|
|||
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().
|
#9
|
|||
|
|||
can i use {vb:raw GLOBALS.title} ?
|
#10
|
|||
|
|||
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?
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|