View Full Version : Include php page
Silver89
11-15-2009, 10:05 PM
I'm trying to include a php file with the following code as documented on the vBulletin pages, my plugin is setup as:
ob_start();
include('/header.php');
$globalHeader = ob_get_contents();
ob_end_clean();
I then write - $globalHeader - in the header file where I want this include to appear? I have it setup with the host location of global_start but at the moment it just shows $globalHeader on screen and I'm not sure what's wrong?
Many Thanks
Dismounted
11-16-2009, 03:53 AM
The way variables are used in templates has changed in vBulletin 4. You must register any variables before using them and address them like so: {vb:raw globalHeader}
$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header', $preRegister);
Silver89
11-16-2009, 04:05 AM
Okay I have managed to get the php include for 4.0 working with the following code:
Template:
{vb:raw globalHeader}
Plugin:
ob_start();
include("../header.php");
$globalHeader = ob_get_contents();
ob_end_clean();
$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header', $preRegister);
However what I really want to do is basically create my own custom template page, the problem with this current include is that the vb code inside ../header.php is just printed instead of being executed, what can I do to fix this?
Many Thanks
cory_booth
11-16-2009, 08:34 AM
Along the same lines....
What would be the easiest way to include php pages in the CMS?
For example, I run HamWeather on my site. PReviosuly - using vbAdvanced - I made some templates that called in php files to display the weather. Can I do the same via CMS?
Something like this for example:
<?php
$doPrintNWS = false;
require("/home1/mysite/public_html/modules/advforecast.php"); ?>
<html>
<body style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; background-color:#F5F5FF">
<table style="font-size:9px;">
<tr align="center" valign="top">
<?php print "<td>$forecasticons[0]</td><td>$forecasticons[1]</td><td>$forecasticons[2]</td><td>$forecasticons[3]</td><td>$forecasticons[4]</td><td>$forecasticons[5]</td><td>$forecasticons[6]</td><td>$forecasticons[7]</td>\n"; ?>
</tr>
<tr align="center" valign="top">
<?php print "<td>$forecasttemp[0]</td><td>$forecasttemp[1]</td><td>$forecasttemp[2]</td><td>$forecasttemp[3]</td><td>$forecasttemp[4]</td><td>$forecasttemp[5]</td><td>$forecasttemp[6]</td><td>$forecasttemp[7]</td>\n"; ?>
</tr>
</table>
</body>
</html>
Red Spider
12-05-2009, 02:50 PM
Okay I have managed to get the php include for 4.0 working with the following code:
Template:
{vb:raw globalHeader}
Plugin:
ob_start();
include("../header.php");
$globalHeader = ob_get_contents();
ob_end_clean();
$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header', $preRegister);
copied word for word and just changed the variable name - but wont work - any ideas?
Lynne
12-05-2009, 04:15 PM
vB_Template::preRegister('header', array('globalHeader' => $globalHeader));
Red Spider
12-05-2009, 04:33 PM
vB_Template::preRegister('header', array('globalHeader' => $globalHeader));
thanks Lynne, but that doesnt work either :'(
Lynne
12-05-2009, 04:49 PM
It doesn't help when you just say something doesn't work. The best thing to do is say "This is my exact code in the ____ hook location {post code} and this is exactly what I have in my template {post about five lines above and below added code also}."
My guess would be you don't have the correct hook location. Did you look in the code to see where the header is rendered? And then looked above the code to pick a hook above there? Or did you just randomly pick a hook location?
rudejason
12-07-2009, 01:34 PM
copied word for word and just changed the variable name - but wont work - any ideas?
THANK YOU SO MUCH!!!! i have looked for about 3 hrs total on how to make this work!
All i could find on this board was a link to the manual. That guy that always posts the link and says stuff about people must not like the manual needs to up date it with the code on how to use the variables in the template. I bet then he would no longer need to post the link.
Thanks again!
Tom McConnell
01-04-2010, 07:35 PM
Example above:
{vb:raw globalHeader}
This is put in the vb "footer" template:
{vb:raw myname_footer}
Plugin code above:
ob_start();
include("../header.php");
$globalHeader = ob_get_contents();
ob_end_clean();
$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header', $preRegister);
Plugin code in my plugin named "myname_footer":
ob_start();
include("../header.php");
$myname_footer = ob_get_contents();
ob_end_clean();
$preRegister['myname_footer'] = $myname_footer;
vB_Template::preRegister('footer', $preRegister);
Notice last line template name change.
Change "myname_footer" to what you like.
Red Spider
01-04-2010, 08:02 PM
hi tom, i'm confused by your post - i'm trying to do a header include
grimwolge
03-01-2010, 07:11 PM
ob_start();
include("../header.php");
$myname_footer = ob_get_contents();
ob_end_clean();
$preRegister['myname_footer'] = $myname_footer;
vB_Template::preRegister('footer', $preRegister);
What file, or where? does this get inserted into?
When I was running vBulletin 3.x it went into global.php
But now that i've upgraded to vBulletin 4, I don't know where that code goes.
Thanks
Nick
manuel.ho
03-24-2010, 12:07 AM
intente con todas las variaciones seƱaladas aquĆ. Alguien ha logrado hacer esto con exito?
Jamie G
03-28-2010, 12:30 AM
Hi guys.
Trying to get some php code into my forum to get it to display the frontpage slider.
I've done this.
ob_start();
include('ss.php');
$slider = ob_get_contents();
ob_end_clean();
$preRegister['slider'] = $slider;
vB_Template::preRegister('forumhome', $preRegister);
Still can't get it to display at all!
What am i doing wrong?
Lynne
03-28-2010, 01:40 AM
Just noticing the obvious error, but the name of the template is not forumhome, it is FORUMHOME.
Jamie G
03-28-2010, 01:58 AM
Still doesn't work.... Ok,
So let's start from scratch.
I have this.
?php
// START of "Frontpage Slideshow" settings
$nameOfSlideshowToDisplay = "myslideshow"; // Enter the name of your slideshow. Slideshows are in folders inside /fpss/slideshows/.
$URLofyoursite = "http://www.******.com"; // Enter your site's URL.
$AbsoluteServerPathofyoursite = "/***/***/public_html"; // Enter the root path of your site on the server.
// do not edit below this line
include_once($AbsoluteServerPathofyoursite."/fpss/mod_fpslideshow.php");
// END of "Frontpage Slideshow" settings
?>
It tells me I should put this where I wish for it to call for the frontpage slideshow. I'd like it just below the navbar. But I can't put PHP in the template. So I've taken that above code and saved it as ss.php.
So I've gone into add plugin, and done the following.
ob_start();
include('ss.php');
$slider = ob_get_contents();
ob_end_clean();
$preRegister['slider'] = $slider;
vB_Template::preRegister('FORUMHOME', $preRegister);
I've then saved the plugin and gone into FORUMHOME and entered
{vb:raw slider}
I still have nothing appear. Hopefully with this full view of what I've done, you may be able to assist me in getting this working as It's getting annoying now!
This works perfectly! Thanks!
Example above:
{vb:raw globalHeader}
This is put in the vb "footer" template:
{vb:raw myname_footer}
Plugin code above:
ob_start();
include("../header.php");
$globalHeader = ob_get_contents();
ob_end_clean();
$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header', $preRegister);
Plugin code in my plugin named "myname_footer":
ob_start();
include("../header.php");
$myname_footer = ob_get_contents();
ob_end_clean();
$preRegister['myname_footer'] = $myname_footer;
vB_Template::preRegister('footer', $preRegister);
Notice last line template name change.
Change "myname_footer" to what you like.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.