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

Can you use PHP code in Smarty templates?

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-18-2002, 09:23 AM
 
AJ AJ is offline
 

Member
  
Join Date: Oct 2002
Location: Marietta, Ohio
Posts: 25
 

Default Can you use PHP code in Smarty templates?

I'm sure this is a question that's been asked before, but I can't find an answer.

Can you use PHP code inside a .tpl file, or at least include a php file? I tried <?php include("somefile.php") ?> and it didn't parse the PHP at all.

I have some very specific mods I need to make that require custom PHP code. I have no time or desire to learn the Smarty syntax and was desperately hoping I could just use PHP.

Frankly when I bought X-Cart I thought it would be mostly PHP-based, so all this Smarty code has thrown a wrench into my schedule.

Thanks for any help.
__________________
Andrew
Webdev/Designer/Filmmaker
http://www.jstudios.com
Reply With Quote
  #2  
Old 10-18-2002, 10:29 AM
 
syddos syddos is offline
 

eXpert
  
Join Date: Sep 2002
Location: London, England, UK
Posts: 259
 

Default

Hi AJ,

I joined this forum about a week after it was launched, and I have never seen this question asked.

I have struggled to learn bits of smarty, and php to create most of my mods. I remember reading that you can include php in the templates, but it should be avoided, so I have done the opposite in my latest mods, I have put HTML in my own created PHP files, this way you reduce problems with future upgrades of xcart. My latest mod is more of a plugin to xcart, so 99% of the original xcart files, are still in their original state. Post if you need further info on this method.


Here is the extract and the URL to it's source.

Quote:
It is possible to embed PHP code right in your template files, although this may not be needed (nor recommended) since the engine is so customizable.
(It's 9th in the bullet list )

at http://smarty.php.net/manual/en/what.is.smarty.html

Regards,
__________________
Syddos

Nothing is impossible, We just don't know how to do it ........Yet!

Xcart 4.1.X PRO (Testing Platform: winXP Pro)
Perl 5.8.7 (win32)
WINAMP 1.6.3 (win32 server package. Includes the following)
- phpMyAdmin v2.8.03
- MySql 5.0.21
- Apache 2.0.55 (win32)
- php 5.1.4
- SQLitemanager 1.2.0
Reply With Quote
  #3  
Old 11-22-2002, 07:35 AM
 
AJ AJ is offline
 

Member
  
Join Date: Oct 2002
Location: Marietta, Ohio
Posts: 25
 

Default

Since I haven't seen anyone post a solution on this, I'll post a couple methods I'm using.

To include a php file in a Smarty .tpl file, just do this:

{include_php file="/pathtofile/file.php"}

This seems to work pretty well, assuming you don't need to use any variables from Smarty.

You can also use actual PHP code too! Just do it like this:

{php}
php code goes here;
{/php}

For this to work, you have to set the $php_handling variable to SMARTY_PHP_ALLOW in /Smarty-2.1.1/Smarty.class.php.

Hope that helps someone out there. Took me forever to figure it out. Now, if someone can tell me how to pass a Smarty-defined variable to an included PHP script, I'd love to hear it!
Reply With Quote
  #4  
Old 11-22-2002, 01:39 PM
 
syddos syddos is offline
 

eXpert
  
Join Date: Sep 2002
Location: London, England, UK
Posts: 259
 

Default

Hi,

try
Quote:
{include_php file="/pathtofile/file.php" $your_variable="this_value"}

or
Quote:
{include_php file="/pathtofile/file.php" $your_other_variable=$this_smarty_assigned_variabl e}

I have not tried this with an "include_php file", as I try to keep php out of the templates.

Regards,
__________________
Syddos

Nothing is impossible, We just don't know how to do it ........Yet!

Xcart 4.1.X PRO (Testing Platform: winXP Pro)
Perl 5.8.7 (win32)
WINAMP 1.6.3 (win32 server package. Includes the following)
- phpMyAdmin v2.8.03
- MySql 5.0.21
- Apache 2.0.55 (win32)
- php 5.1.4
- SQLitemanager 1.2.0
Reply With Quote
  #5  
Old 11-26-2002, 05:52 AM
 
AJ AJ is offline
 

Member
  
Join Date: Oct 2002
Location: Marietta, Ohio
Posts: 25
 

Default

Unfortunately, neither of those methods work.
Reply With Quote
  #6  
Old 03-19-2003, 04:39 PM
 
maniac maniac is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 97
 

Default Same issue...

I just posted the same question on the editing templates forum, did'nt realize it was here...

Did you find a solution?
Reply With Quote
  #7  
Old 03-20-2003, 05:31 AM
 
maniac maniac is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 97
 

Default

Quote:
Originally Posted by AJ
This seems to work pretty well, assuming you don't need to use any variables from Smarty.

Does anyone know if there is a comprehensive list of the variables Samrty uses?
Reply With Quote
  #8  
Old 02-25-2004, 10:42 PM
  BoomBoomBap's Avatar 
BoomBoomBap BoomBoomBap is offline
 

Senior Member
  
Join Date: Nov 2002
Location: San Francisco
Posts: 184
 

Default

http://smarty.php.net is your friend.

With regards to this topic the following links are especially helpful:

http://smarty.php.net/manual/en/variable.php.handling.php

http://smarty.php.net/manual/en/language.function.fetch.php

The fetch command allowed me to include a php file !

Joy

__________________
Site 1 > XCART LIVE 3.4.12

Site 2 > XCART LIVE 4.0.17
Reply With Quote
  #9  
Old 04-03-2004, 01:47 AM
 
ATKOgirl ATKOgirl is offline
 

X-Adept
  
Join Date: Sep 2002
Posts: 448
 

Default

Hi,

Can I use a smarty variable in the php file name when I am using include_php:

Code:
{include_php file="http://www.mysite.com/d/{$product.productcode}.php"}

It doesn't seem to work the way I have it set above.

Any help is greatly appreciated.

ATKOgirl
Reply With Quote
  #10  
Old 04-03-2004, 02:43 AM
 
ATKOgirl ATKOgirl is offline
 

X-Adept
  
Join Date: Sep 2002
Posts: 448
 

Default

I've also tried it this way and it didn't work:

Code:
{php} include("http://www.mysite.com/d/{$product.productcode}.php"); {/php}


I get the following error:

Parse error: parse error, expecting `'}'' in /home/bbdeals/public_html/templates_c/189/1894910960/0.php on line 119



ATKOgirl
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 11:22 AM.

   

 
X-Cart forums © 2001-2020