PDA

View Full Version : Parse PHP in a Template


TLCanna
03-03-2004, 12:58 PM
I have recently upgraded to VB3, my old boards had a banner rotator.php that was included in my header template.

My Problem:
When I do a PHP include like so <? include ("rotator.php");?> it displays the text on the screen. It doesn't actually parse the code and randomly rotate my banners.

Is there a command to force the template to parse the php code?

NTLDR
03-03-2004, 01:01 PM
You can only parse PHP code in the phpinclude_start and phpinclude_end templates.

TLCanna
03-03-2004, 01:03 PM
Do you indcate it to be parsed by a PHP command or what?

NTLDR
03-03-2004, 01:10 PM
You just place your PHP in the template as if it was a .php file.


include('rotator.php');

TLCanna
03-03-2004, 01:38 PM
Thanks NTLDR... That worked, but now I have a second question. While reading the help screen for phpinclude_start.... It says You can enter PHP code here. The phpinclude_start template is evaluated at the beginning of page execution and can be used for putting things into templates.

So it sounds like I can now include the phpinclude_start to any template and it can be be displayed accordingly.

My questions is, what is the syntax for inserting to a template, should I say include or drop it in as a variable in the template.

Anna

PS... Let me apologize in advance for dumb questions, my technical skills are green at best.

:)

NTLDR
03-03-2004, 01:55 PM
If you follow the example in there:


// Example of how to include a seperate file:
ob_start();
require("yourheader.html");
$headercontent = ob_get_contents();
ob_end_clean();


You could then put $headercontent (which should work in most cases, some templates will require $GLOBALS[headercontent]) will place the HTML found in yourheader.html where you have placed the variable.

ixian
03-06-2004, 04:39 AM
I have a similar problem, but I'm having some difficulty.

The problem is, I'm trying to get a php script that makes it's own call to a different database on the same server, called "center".

The phpinclude_start statement looks like this:

ob_start();
require_once ('../center/activity.php');
$activity1 = ob_get_contents();
ob_end_clean();


But when that happens, I get database errors on my forums, saying it can't find variable this, variable that - it looks like once it switches to my "center" database it doesn't switch back to the vbulletin db.

I tried using

chdir("$/var/www/html/forums");

After the above include, but that did nothing.

Anyone have any ideas? I'm sure I'm doing something wrong here. I tried using "include" and "require" above as well.

NTLDR
03-06-2004, 06:37 PM
Whats the code in center.php? If it doesn't echo/print etc anything directly out then you just need the require_once() part in the php_include_start template.

ixian
03-06-2004, 08:28 PM
It does echo/print stuff out, which is the problem.

I finally solved this by moving the table it uses over to the vbulletin database, and using it instead. It's a small, simple table with 3 rows and not a lot of information, so load isn't an issue, and it works now.

Kind of in-elegant for other types of php scripts though, but what can you do.