vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How to print Forum ID? (https://vborg.vbsupport.ru/showthread.php?t=269529)

greytone 09-01-2011 08:58 PM

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!

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:

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.

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

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

Quote:

Originally Posted by ltwinnerr (Post 2242797)
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

Quote:

Originally Posted by behcet (Post 2502046)
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?


All times are GMT. The time now is 09:20 AM.

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.01199 seconds
  • Memory Usage 1,733KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete