Danish Khan Danish Khan - 4 months ago 24
Smarty Question

Smarty template file (.tpl) is not loading PHP code

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.

Answer

Its

{include_php file="templates/sfunc.php"}

instead of

{include_php 'templates/sfunc.php';}

(Given that the path templates/sfunc.php is correct)