PDA

View Full Version : Use of php within template?


agiacosa
02-27-2005, 02:56 PM
Anyone figure out how to use PHP within a template other than phpinclude?

Dean C
02-27-2005, 03:18 PM
It's not reccomended, and theres no need for it really :)

agiacosa
02-27-2005, 03:28 PM
There is. I am doing a custom page that needs to pull information from MySQL database and then echo out.

Dean C
02-27-2005, 03:38 PM
Then do so within the custom page ;) There's no need at all to put anything other than the odd if conditional and html in a template.

agiacosa
02-27-2005, 03:55 PM
I need to have the same header and footer and sessions that I get when doing a custom page using Gary's or Logician's templating system.

Dean C
02-27-2005, 03:56 PM
Sorry I fail to see how having PHP in the template is going to benefit you here. If you're using vB's template system you can put $header, $footer in your custom template. Also you instantly have access to everything you would on a normal vB page.

agiacosa
02-27-2005, 04:10 PM
Dean,

I am not getting my question across well.

I have a script that is built using php (index.php). It includes a database config file (db.php) makes selection queries from a database, presents selection options to the user and then displays the result of that query. Basically, it is the user interface for an aquarium plant database for our members. I want to have this interface within vB so that members stay logged in, I can see they are there in WOL, use user permissions and just have the same look of the site.

My understanding is that I can't do this within a template. How else can I do this?

Michael Morris
02-27-2005, 08:39 PM
Dean,

I am not getting my question across well.

I have a script that is built using php (index.php). It includes a database config file (db.php) makes selection queries from a database, presents selection options to the user and then displays the result of that query. Basically, it is the user interface for an aquarium plant database for our members. I want to have this interface within vB so that members stay logged in, I can see they are there in WOL, use user permissions and just have the same look of the site.

My understanding is that I can't do this within a template. How else can I do this?

Put your custom script in PHP and send it's output to a variable. Do this in the following manner:

ob_start();
include('yourheader.html');
$your_code = ob_get_contents();
ob_end_clean();


Then place $your_code in the header or footer template.

cinq
02-27-2005, 11:19 PM
Dean,

I am not getting my question across well.

I have a script that is built using php (index.php). It includes a database config file (db.php) makes selection queries from a database, presents selection options to the user and then displays the result of that query. Basically, it is the user interface for an aquarium plant database for our members. I want to have this interface within vB so that members stay logged in, I can see they are there in WOL, use user permissions and just have the same look of the site.

My understanding is that I can't do this within a template. How else can I do this?

Yes you can still throw all the code into a php file like Dean mentioned, and output the output by calling a template to show the page.