php code not working in tpl files why?


could anyone tell me please how i use php code in tpl files.

i already tried several methods but till yet no success…


i add php code in seperate file like…

$smarty = new Smarty();

$smarty->assign('firstname', 'Doug');
$smarty->assign('lastname', 'Evans');
$smarty->assign('meetingPlace', 'New York');



than call variables in index.tpl but no success after that i use above code in tpl file and call variables in same file like code below


$address_comp = 'testing address by ali';

$smarty = new Smarty();

$smarty->assign('name', 'Doug');

$smarty->assign('address', 'test address');

$smarty->assign('state', 'colorado');


Name: {$name}

Address: {$address}

State: {$state}

You're not making a lot of sense with your samples and also, please use 'code' tags so ti's readable.

In a php file, you should be using:

Not a new instance of the template like:

$smarty = new Smarty;

The latter will give you a private copy of what $smarty points to and will not end up in the template engine for the pages being rendered…

I'm not really sure what you are asking either, but if you want to use PHP in your templates, you will probably need to change:

'allow_php_in_templates' => false, // Allow to use {php} tags in templates


'allow_php_in_templates' => true, // Allow to use {php} tags in templates

In you config.local.php file.

Hope that helps,


thanks for helping me but the following code is not available in config.local.php

[color=#008800]'allow_php_in_templates'[/color][color=#000000] [/color][color=#666600]=>[/color][color=#000000] [/color][color=#000088]false[/color][color=#666600],[/color][color=#000000] [/color][color=#880000]// Allow to use {php} tags in templates[/color]

Are you on an older version of CS-Cart?

I think this used to be in 2 different places depending on the version. I think it used to be at the bottom of config.local.php and I think it might have been in config.php

You should have something in one of those files like:

$config['tweaks'] = array (

There should be a list of tweaks. Just add this one to that list:

'allow_php_in_templates' => true, // Allow to use {php} tags in templates

Hope that helps,


I believe in the older versions it was on by default and only became configurable in the 2.1 timeframe… But that is a guess.