Back to vBulletin 4 Articles

[vBulletin 4] Simple way of including an external PHP file
by Crimm 14 May 2010
Rating: (3 votes - 5.00 average)

There are other articles out there on variables, templates, etc on vBulletin 4. This is a simple example of including an external PHP files like you used to be able to do here:

http://www.vbulletin.com/forum/showthread.php?173937-How-to-Include-a-PHP-or-HTML-File

Thanks to this Blog post by David IB http://www.vbulletin.com/forum/entry.php?2387-Pushing-your-variables-to-templates and this article by cellarius [HOW TO - vB4] Rendering templates and registering variables - a short guide

I have figured out it's only a simple extra step.

Step 1: Create a new plugin
  • Hook Location: What area of the forums you want this variable to appear. Don't know where? Use global_start
  • Title: Give it a title
  • Execution order: Your choice
  • Plugin PHP Code:

    Code:
    ob_start();
      require_once('LOCATION OF EXTERNAL FILE');
      $php_include = ob_get_contents();
    ob_end_clean();
    vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));

Step 2: You will have to figure out these two entries for yourself: LOCATION OF EXTERNAL FILE & Hook Location

To give you an example of what you should use is that if you want to display your external PHP file on your Forum's Home. Then replace these two with these values:

Hook Location with forumhome_start
TEMPLATE YOU ARE USING with FORUMHOME

Keep in mind that global_start will still be acceptable, but it's extra loading time where it's not needed. Therefore choosing the optimum hook location is better for your performance overall.

Step 3: Visit the Style Manager -> TEMPLATE YOU ARE USING and place the variable in your style where you want it. You will have to use the new format.

Code:
{vb:raw php_include}
That's it - Pretty simple; see?

Notes, If you want to:

Include this PHP file in multiple templates then preRegister it for the multiple templates:

Code:
vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));
vB_Template::preRegister('TEMPLATE YOU ARE USING 2',array('php_include' => $php_include));
Thanks to http://www.vbulletin.com/forum/entry.php?2387-Pushing-your-variables-to-templates again.

I'm still learning as I go with vb4, but if I learn some more notes to add... I'll drop by here.

I hope that helps some one out there!

vblts.ru supports vBulletin®, 2022-2024