PHP code in template

Is there a way to run PHP code in the templates? For example:



```php if ($var = ‘static_value’) {

echo ‘

That is correct.

’;

} ```

[quote name=‘smoked1’]Is there a way to run PHP code in the templates? For example:



```php if ($var = ‘static_value’) {

echo ‘

That is correct.

’;

} ```[/QUOTE]





It’s easy to do in this way:



Create a “yourphpfile.php” and include all your code inside it; then put it in CS-Cart’s root.



Now you can include this file into your .tpl template file using this line of code:



{include_php file="yourphpfile.php"}




Best Regards

Sweet. Thanks. Can that file also use the Smarty Variables?

[quote name=‘smoked1’]Sweet. Thanks. Can that file also use the Smarty Variables?[/QUOTE]



You are welcome!



I think it’s not possible, because in that file you are using only standard PHP…but I’m not totally sure :slight_smile: (maybe it could be possibile to include smarty classes in that file…)



Regards

you can insert php code right into your tpl file without including a separate file by using the tags



{php}

your php code here

{/php}



You CAN also assign tpl variables to php like this:



{assign var=smarty_var_get value=$cart.total}



{php}

$price = $this->get_template_vars(‘smarty_var_get’);

{/php}