PDA

View Full Version : Include php page


Silver89
15 Nov 2009, 23:05
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

kh99
15 Nov 2009, 23:22
nvm

Dismounted
16 Nov 2009, 04:53
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
16 Nov 2009, 05:05
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
16 Nov 2009, 09:34
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
05 Dec 2009, 15:50
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
05 Dec 2009, 17:15
vB_Template::preRegister('header', array('globalHeader' => $globalHeader));

Red Spider
05 Dec 2009, 17:33
vB_Template::preRegister('header', array('globalHeader' => $globalHeader));

thanks Lynne, but that doesnt work either :'(

Lynne
05 Dec 2009, 17:49
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
07 Dec 2009, 14:34
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
04 Jan 2010, 20:35
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
04 Jan 2010, 21:02
hi tom, i'm confused by your post - i'm trying to do a header include

grimwolge
01 Mar 2010, 20:11
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
24 Mar 2010, 01:07
intente con todas las variaciones señaladas aquí. Alguien ha logrado hacer esto con exito?

Jamie G
28 Mar 2010, 01:30
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
28 Mar 2010, 03:40
Just noticing the obvious error, but the name of the template is not forumhome, it is FORUMHOME.

Jamie G
28 Mar 2010, 03:58
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!

hydn
05 May 2010, 21:33
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.