X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   How to include a PHP file into a .TPL (https://forum.x-cart.com/showthread.php?t=18984)

2tmoto 01-02-2006 04:18 AM

How to include a PHP file into a .TPL
 
I have a file called incdist.php with this code:

Code:

<?php
##################################################################################################  Configuration
#################################################################################################                                                                                                             

$server = "localhost";                         
$db_user = "user";
$db_pass = "password";
$database = "database";

#  End Configuration - DO NOT EDIT BEHIND THIS LINE !!!
#################################################################################################                                                                                                             

mysql_connect($server, $db_user, $db_pass) or die ("Database CONNECT Error");                                                                 

$sql = "SELECT id, provincia, nombre, calle, poblacion, codpos, telefono, contacto, productos, CIF, visible FROM distribuidores where visible=1 ORDER BY provincia ASC";
mysql_db_query($database, $sql) or die("Database Select Error");
$result = mysql_query($sql) or print(mysql_error());

echo "<table width=\"95%\"  border=\"1\" cellspacing=\"0\" cellpadding=\"1\" align=\"center\" >\n\r";
echo "<tr><td><u>PROVINCIA</u></td><td><u>DISTRIBUIDOR</u></td><td><u>DIRECCION</u></td><td><u>CONTACTO</u></td><td><u>PRODUCTOS</u></td></tr>\n\r";

while ($arow = mysql_fetch_array($result)) {

echo "<tr><td>$arow[provincia]<td>$arow[nombre]<td>$arow[calle]
$arow[codpos] $arow[poblacion]<td>$arow[telefono]
$arow[contacto]<td>$arow[productos]</td>\n\r";
echo "</tr>\n\r";
} //end while
echo "</table>";
?>



This file runs perfect by itself. I have tried to included on a .TPL using this code

Code:

{php}
include('incdist.php');
{/php}



It doens't work. Browser keeps running and running.... Nothing is coming out.

Any clue?????

Dave

X-CART PRO 4.0.17

balinor 01-02-2006 04:33 AM

Make sure you include the path to the external php file correctly and use " to surround it instead of '.

2tmoto 01-02-2006 04:41 AM

The TPL file is on /skin1/customer/main/dist.tpl
and the php is on /incdist.php

is that the correct path?


Thanks

Dave

X-CART PRO 4.0.17

balinor 01-02-2006 04:43 AM

No, you'll need to put it in the skin1 directory.

2tmoto 01-02-2006 07:01 AM

Now I get this errors:

Warning: Smarty error: file:incdist.php is not readable in /www/www.domain.com/xcart/Smarty-2.6.9/Smarty.class.php on line 1088

Warning: _include(): Failed opening '' for inclusion (include_path='/www/www.domain.com/xcart/modules/Special_Offers:/www/www.2tmoto.com/xcart/include/template in /www/www.2tmoto.com/xcart/Smarty-2.6.9/Smarty.class.php on line 1915


I am totally lost....

We are migrating pages from our old store to xcart, and we have problems with all php pages.

Thanks

Dave

X-CART PRO 4.0.17

balinor 01-02-2006 11:15 AM

Are the permissions set properly?

2tmoto 01-02-2006 10:55 PM

File permissions are set as any other file.
What am I doing wrong?

I just want to insert a php file in a template. It is possible, isn't it?

Thanks,

Dave

X-CART PRO 4.0.17

geckoday 01-03-2006 10:14 AM

The error is showing that you probably don't have your file in any directory on the include path. This is a little confusing because you are trying to do something in a way Smarty never intended it to be done. To do it the Smarty way you should be modifiying one of the X-Cart PHP files to get the data from the DB and make it available to the Smarty template and using the template to generate the HTML.

That said, I think the root of the problem doing it your way is that using the Smarty PHP tag is using the include path available at template execution time not at template compile time like a Smarty include. There are two things you can try.

Specify the full path like this:

Code:

{php}
include('{$SkinDir}/incdist.php');
{/php}


Or try using a Smarty include instead:

Code:

{include file="incdist.php.tpl"}

Then make file incdist.php.tpl your incdist.php file with the {php} and {/php} tags in it.

HTH


All times are GMT -8. The time now is 01:20 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.