Log in

View Full Version : putting PHP in style templates


RossOliver
10-11-2005, 08:03 PM
Hey,

How can I include a PHP script in the navbar style template?

Alternatively, where can I find the navbar template in a PHP file rather than through the admin cpanel...

Cheers,

-Ross

Andreas
10-11-2005, 08:05 PM
1) You can't use PHP in Templates
2) Templates are stored in the Database (table template) and not in files.

untold4you
10-11-2005, 08:10 PM
How can I include a PHP script in the navbar style template? php in a template is not possible, you can however output strings into it.

Check this topic, you will learn much on how vb works:
https://vborg.vbsupport.ru/showpost.php?p=791513&postcount=1

Alternatively, where can I find the navbar template in a PHP file rather than through the admin cpanel...
You can't cause all templates are located in the database and not in the form of a file.

RossOliver
10-11-2005, 08:35 PM
urgh, I can't get my head round this :ermm:

Ok, I have my php script which now just returns a load of HTML in a single variable.

What I don't understand is how to get that variable into the template. Do I some how use an 'xml hook' so I could include it something like;

<myphpscript>
parameters here if I want...
</myphpscript>

If that is the case, is there some kind of template I can alter that will show me the basic idea of how to do this?

Thanks,

-Ross

Andreas
10-11-2005, 08:42 PM
This is a FAQ ;)

global_start

ob_start();
include('/path/to/script.php');
$script_output = ob_get_contents();
ob_end_clean();

KW802
10-11-2005, 08:43 PM
In short... normally you can use PHP in HTML like you're thinking but you can't do it in vB templates... if you dig around either vB.org or vB.com you'll come across a thread where it's discussed that the ability of doing PHP in templates is prevented for security concerns.

To do what you want... are you trying to show a new page using vB's header & footer (and style) or are you trying to just include one or two new fields on an existing vB page somewhere?

RossOliver
10-11-2005, 08:45 PM
Alright, but where does that go and how does it make it's way into the template? :o

Cheers,

-Ross

In short... normally you can use PHP in HTML like you're thinking but you can't do it in vB templates... if you dig around either vB.org or vB.com you'll come across a thread where it's discussed that the ability of doing PHP in templates is prevented for security concerns.

To do what you want... are you trying to show a new page using vB's header & footer (and style) or are you trying to just include one or two new fields on an existing vB page somewhere?

I'm just trying to include a few lines of returned text in a div table under the navbar...

-Ross

Andreas
10-11-2005, 08:47 PM
As said - global_start.
Then just use the variable created by your script (and/or $script_output if it directly generates output) in the Template you want it.

RossOliver
10-11-2005, 09:07 PM
Ah ok I think I understand now - but I think im going crazy, what on earth is 'global_start'? a file, template, something in the admincp :ermm:

-Ross

Andrew
10-11-2005, 11:18 PM
'global_start' is a hook location where you can place PHP code that will be ran on every page - You can add a hook to it in the AdminCP under 'Plugin System > Add New Plugin'

RossOliver
10-12-2005, 06:10 AM
'global_start' is a hook location where you can place PHP code that will be ran on every page - You can add a hook to it in the AdminCP under 'Plugin System > Add New Plugin'

I know I'm being really stupid - but I don't see a 'plugin system' option down the left column, or in the 'vBulletin options' section :o

I am looking in the right place, right...there should be a 'plugin system' bit on the left column which I click to expand more options and 'add new plugin' should be one of those options?

-Ross

[edit]

I just found this;

'From version 3.5, vBulletin has an extensive plugin system, allowing new features to be added and functionality to be changed by third-party add-ons, without modifying the core vBulletin code.'

I am using vBulletin 3.0.8, is there a similar option for me?

beacher
10-12-2005, 06:50 AM
no only the 3.5.0 version has the plugin system. ;)

Andreas
10-12-2005, 09:48 AM
In vBulletin 3.0, you can use Template phpinclude_start (one of the 2 templates where you can use PHP) similar to Hook global_start.

RossOliver
10-12-2005, 10:54 AM
ok, I think I'm almost there. In the phpinclude_start template I have this;


/*
// Example of how to include a seperate file:

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

// Now place a reference to $your_code where you want the resulting HTML to be displayed.
// This will most likely be the header or footer template.
*/

<!-- recent wiki changes -->

ob_start();
include('./includes/wiki_recent_changes.php');
$script_output = ob_get_contents();
ob_end_clean();

<!-- /recent wiki changes -->



The file wiki_recent_changes.php just echo's the html I want to display in the navbar template. The navbar template now has this;


<!-- wiki recent activity -->

<div style="float:center; background-color:#FFFFFF; border:1px solid #AAAAAA; margin-top:-20px;">

<span style="padding:5px;">
$script_output
</span>

. . . etc


Is this looking right?

Thanks again,

-Ross

ok, I think I'm almost there. In the phpinclude_start template I have this;


/*
// Example of how to include a seperate file:

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

// Now place a reference to $your_code where you want the resulting HTML to be displayed.
// This will most likely be the header or footer template.
*/

<!-- recent wiki changes -->

ob_start();
include('./includes/wiki_recent_changes.php');
$script_output = ob_get_contents();
ob_end_clean();

<!-- /recent wiki changes -->



The file wiki_recent_changes.php just echo's the html I want to display in the navbar template. The navbar template now has this;


<!-- wiki recent activity -->

<div style="float:center; background-color:#FFFFFF; border:1px solid #AAAAAA; margin-top:-20px;">

<span style="padding:5px;">
$script_output
</span>

. . . etc


Is this looking right?

Thanks again,

-Ross

[edit]

Nevermind, I just hard-coded it into global.php....