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)
-   -   Can you use PHP code in Smarty templates? (https://forum.x-cart.com/showthread.php?t=342)

AJ 10-18-2002 09:23 AM

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.

syddos 10-18-2002 10:29 AM

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,

AJ 11-22-2002 07:35 AM

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!

syddos 11-22-2002 01:39 PM

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,

AJ 11-26-2002 05:52 AM

Unfortunately, neither of those methods work.

maniac 03-19-2003 04:39 PM

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

Did you find a solution?

maniac 03-20-2003 05:31 AM

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?

BoomBoomBap 02-25-2004 10:42 PM

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

:)

ATKOgirl 04-03-2004 01:47 AM

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

ATKOgirl 04-03-2004 02:43 AM

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


All times are GMT -8. The time now is 12:29 PM.

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