View Full Version : PHP into Templates
Sergio68
Tue 24th Oct '06, 12:50pm
I'd like to built a personal vBMenu into the navbar and I'm following this example : http://www.vbulletin.com/docs/html/templates_vbmenu_example
<if condition="$show['popups']">
<!-- start vBMenu control element -->
<table class="tborder" cellpadding="4" cellspacing="1">
<tr>
<td id="MyMENU" class="vbmenu_control">
<a href="#">Second Multiple Popup Control</a>
<script type="text/javascript">
<!--
vbmenu_register("MyMENU");
//-->
</script>
</td>
</tr>
</table>
<!-- end vBMenu control element -->
<!-- start vBMenu popup element -->
<div class="vbmenu_popup" id="MyMENU_menu" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="thead">This is my example vBMenu</td>
</tr>
<tr>
<td class="vbmenu_option"><a href="index.php">Home Page</a></td>
</tr>
<tr>
<td class="vbmenu_option"><a href="usercp.php">User CP</a></td>
</tr>
</table>
</div>
<!-- end vBMenu popup element -->
<else />
<!-- start alternative, non-vBMenu content -->
<table class="tborder" cellpadding="4" cellspacing="1">
<tr>
<td class="vbmenu_control"><a href="index.php">Home Page</a></td>
<td class="vbmenu_control"><a href="usercp.php">User CP</a></td>
</tr>
</table>
<!-- end alternative content -->
</if>
What I need to do now is to generate a dinamic menu with PHP reading a Data Base. How can I insert <?PHP ?> code into Templates ? Is it possible?
Steve Machol
Tue 24th Oct '06, 3:02pm
Please see these instructions for including PHP, TXT or HTML in a template:
http://www.vbulletin.com/docs/html/templates_externalfiles
http://www.vbulletin.com/forum/showthread.php?p=1066718#post1066718
Sergio68
Tue 24th Oct '06, 4:50pm
Thx, next time I'll search and then I'll ask, later... eventually :D
Sergio68
Thu 26th Oct '06, 8:56pm
Please see these instructions for including PHP, TXT or HTML in a template:
http://www.vbulletin.com/docs/html/templates_externalfiles
http://www.vbulletin.com/forum/showthread.php?p=1066718#post1066718
Ok, I did it as told me on the manual.
I created a Plug-in for global_start with these contents:
ob_start();
include('products.php');
$products = ob_get_contents();
ob_end_clean();
I turned it on.
I created the products.php file with this simple code :
<?php
echo"Hi ! This the message that show the working Plug-in";
?>
Then I inserted the $products variable into this page (http://www.bodyweb.it/prodotti.php) on the central table, but nothing is showed :confused:
Any suggestments?
Lats
Thu 26th Oct '06, 9:01pm
Try assigning the text to a variable, say $my_variable, then display that variable in your template
Sergio68
Thu 26th Oct '06, 9:13pm
Did it, as you can see nothing is showed : http://www.bodyweb.it/prodotti.php
The variables are between the asteriscs.
:confused:
Sergio68
Thu 26th Oct '06, 9:15pm
That's the template :
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle] - Prodotti</title>
$headinclude
<script type="text/javascript" src="./forums/clientscript/vbulletin_global.js"></script>
<script type="text/javascript" src="./forums/clientscript/vbulletin_menu.js "></script>
</head>
$header
$navbar
<table class="tborder" cellpadding="6" cellspacing="1" border="0" width="100%" align="center">
<tr>
<td colspan="2" class="tcat"><div align="center">Prodotti disponibili </div></td>
</tr>
<tr height="5" >
<td width="50%" height="5" align="center" valign="top" class="alt1">
<div align="center"><b>Marche</b>
<br />
<br />
</div></td>
<td width="50%" height="5" align="center" valign="top" class="alt1"><div align="center"><b>Categorie</b></div></td>
</tr>
<tr>
<td height="198" colspan="2" valign="top" class="alt1"><div align="center"><br />
<br />* $products * $my_variable *<br /><br /><br /><br /></div></td>
</tr>
</table>
$footer
</body>
</html>
and this is products.php example file :
<?php
$my_variable="try this text";
echo"Hi ! This the message that show the working Plug-in";
// include 'admin/variabili.php';
// include "$ecommpath/prodotti.php" ;
?>
Lats
Thu 26th Oct '06, 9:19pm
That echo should be causing an error I believe.
Comment that line out.
Sergio68
Thu 26th Oct '06, 10:00pm
Did it, nothing.
I suppose I did something wrong in the vbulletin setting, nothing is passed to it or may be something is missing couse we are outside the "forums/" directory.
Lats
Thu 26th Oct '06, 10:07pm
If it wasn't loading correctly, you would see a bunch of errors on the page. I tried this using the forumhome template and it works well.
You do have the plugin active don't you?
Sergio68
Thu 26th Oct '06, 10:21pm
Yes, plugin active but no errors are showed, that's weird.
Sergio68
Thu 26th Oct '06, 10:28pm
It should be something from the main dir missing couse here it works : http://www.bodyweb.it/forums/prodotti.php but no echo from php file or HTML is showed.
Please don't tell me that I can only pass variables...
Lats
Thu 26th Oct '06, 10:34pm
Errr, you can only pass variables.
You also have some javascript errors on your page - cross_miioroll has no properties
Sergio68
Thu 26th Oct '06, 10:52pm
Errr, you can only pass variables.
The manual says : "Most PHP files that you might wish to include in your forum contain echo or other output statements in your PHP file, it will break vBulletin because it is still in the process of initializing when it loads your PHP file. All echo and other output commands must be output buffered using ob_start, ob_clean, etc. commands. The output of your PHP script will be buffered for later use and inserted into a variable. All other statements in the PHP script will execute normally."
So all the output should be showed, isn't it ? Echoes included.
This is why we got a start, a buffering and a cleaning.
http://www.vbulletin.com/docs/html/templates_externalfiles
Lats
Thu 26th Oct '06, 11:03pm
I'm not familiar with that method - anything I've ever done builds up a variable for display later on in the template.
Sergio68
Thu 26th Oct '06, 11:09pm
If I can't show all the complete output then I have to do built again my php code.
The code is an e-commerce engine wich I call between an header and a footer , I could just use the vbulletin header/footer and all could be ready.
Sergio68
Mon 30th Oct '06, 5:29am
It seems I can show the buffer output now, I don't know how but it works.
Something weird is going on anyway, I included in the template the PHP file with the
ob_start();
include('./products.php');
$products = ob_get_contents();
ob_end_clean();
as told.
This is the file products.php
<?php
$my_variable="1";
echo"2";
include ('textprova.txt');
echo"4";
?>
This is textprova.txt
echo"3";
In the template i show this variables :
$my_variables (that contain One)
and
$products (that should show the buffered output from the included file.
That's what I see :
1 2 echo"3"; 4
instead of
1 2 3 4
Does it make any sense ? :rolleyes:
Sergio68
Tue 12th Dec '06, 6:30pm
Ok, I solvede my problem by using directly the code into the page, without using the template.
That's the http://www.bodyweb.it/prodotti.php page now :
<?php
error_reporting(E_ALL & ~E_NOTICE);
define('NO_REGISTER_GLOBALS', 1);
define('GET_EDIT_TEMPLATES', true);
define('THIS_SCRIPT', 'releases');
$phrasegroups = array();
$specialtemplates = array();
$globaltemplates = array();
$actiontemplates = array();
// require_once('./includes/vba_cmps_include_template.php');
chdir('/srv/www/www.bodyweb.it/forums/');
require_once('./global.php');
// $vbulletin->options['homeurl'];
$navbits = array();
$navbits[''] = 'Prodotti';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// eval('print_output("' . fetch_template('prodotti') . '");');
echo"$stylevar[htmldoctype]
<html dir='$stylevar[textdirection]' lang='$stylevar[languagecode]'>
<head>
<title>$vboptions[bbtitle] - Prodotti - </title>
$headinclude
<script type='text/javascript' src='./forums/clientscript/vbulletin_global.js'></script>
<script type='text/javascript' src='./forums/clientscript/vbulletin_menu.js '></script>
</head>
$header
<br />
<table class='tborder' cellpadding='6' cellspacing='1' border='0' width='100%' align='center'>
<tr>
<td colspan='2' class='tcat'><div align='center'>Prodotti disponibili </div></td>
</tr>
<tr>
<td height='198' colspan='2' valign='top' class='alt1'><div align='center'>";
include('../ecomm/prodotti.php');
echo"<br /></div></td>
</tr>
</table>
$footer
</body>
</html>";
?>
Including "../ecomm/prodotti.php" that can read the data base.
What's the problem now ?
If you click on one of the left link the variable it's unread by the selected page, for example : http://www.bodyweb.it/listamarche.php?marca=Eas
Sergio68
Tue 12th Dec '06, 9:18pm
Done, it was related to register globals.
Powered by vBulletin™ Version 4.0.2 Copyright © 2010 vBulletin Solutions, Inc. All rights reserved.