| ||||||||||
![]() |
Shopping cart software Solutions for online shops and malls | |||||||||
![]() |
![]() |
|
X-Cart Home | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Can you use PHP code in Smarty templates? | ||||
![]() |
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
![]() 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. |
|||||||
#2
|
|||||||
|
|||||||
![]() 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:
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 |
|||||||
#3
|
|||||||
|
|||||||
![]() 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! |
|||||||
#4
|
|||||||
|
|||||||
![]() Hi,
try Quote:
or Quote:
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 |
|||||||
#5
|
|||||||
|
|||||||
![]() Unfortunately, neither of those methods work.
|
|||||||
#6
|
|||||||
|
|||||||
![]() I just posted the same question on the editing templates forum, did'nt realize it was here...
Did you find a solution? |
|||||||
#7
|
|||||||
|
|||||||
![]() Quote:
Does anyone know if there is a comprehensive list of the variables Samrty uses? |
|||||||
#8
|
|||||||||
|
|||||||||
![]() 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 |
|||||||||
#9
|
|||||||
|
|||||||
![]() Hi,
Can I use a smarty variable in the php file name when I am using include_php: Code:
It doesn't seem to work the way I have it set above. Any help is greatly appreciated. ATKOgirl |
|||||||
#10
|
|||||||
|
|||||||
![]() I've also tried it this way and it didn't work:
Code:
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 |
|||||||
|
|||
X-Cart forums © 2001-2020
|