Reputation: 111
I have a smarty template file and I want to include code from a php file. It simply doesn't work. Here's the sfunc.php in templates folder:
function BeautySweet (){
echo 'Script works fine.';
}
?>
Now here's the .tpl file code I added:
{include_php 'templates/sfunc.php';}
{ BeautySweet ();}
I also tried:
{include_php 'sfunc.php';}
{ BeautySweet ();}
Still no luck.
Upvotes: 0
Views: 1544
Reputation: 3245
The use of php in smarty 3+ has been removed and for a good reason, templates are not supposed to have php code. You can use SmartyBC for backwards compatibility of old templates, but if you're creating a new project that's a really bad idea as you will probably have problems in the future. Create a plugin or do the required operations in your php file and pass the result as a variable instead.
Upvotes: 1
Reputation: 6379
Its
{include_php file="templates/sfunc.php"}
instead of
{include_php 'templates/sfunc.php';}
(Given that the path templates/sfunc.php is correct)
Upvotes: 3