Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

How to include a PHP file into a .TPL

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 01-02-2006, 04:18 AM
 
2tmoto 2tmoto is offline
 

Newbie
  
Join Date: Dec 2005
Posts: 5
 

Default 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
Reply With Quote
  #2  
Old 01-02-2006, 04:33 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

Make sure you include the path to the external php file correctly and use " to surround it instead of '.
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #3  
Old 01-02-2006, 04:41 AM
 
2tmoto 2tmoto is offline
 

Newbie
  
Join Date: Dec 2005
Posts: 5
 

Default

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
Reply With Quote
  #4  
Old 01-02-2006, 04:43 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

No, you'll need to put it in the skin1 directory.
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #5  
Old 01-02-2006, 07:01 AM
 
2tmoto 2tmoto is offline
 

Newbie
  
Join Date: Dec 2005
Posts: 5
 

Default

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
Reply With Quote
  #6  
Old 01-02-2006, 11:15 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

Are the permissions set properly?
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #7  
Old 01-02-2006, 10:55 PM
 
2tmoto 2tmoto is offline
 

Newbie
  
Join Date: Dec 2005
Posts: 5
 

Default

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
Reply With Quote
  #8  
Old 01-03-2006, 10:14 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default

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
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 05:05 AM.

   

 
X-Cart forums © 2001-2020