Using PHP code in Smarty tpl FIle

I am new to smarty and I want to use php code in template file i-e tpl file. I have seen the documentation and searched on google but could not find how to use php code they say we need to configure smarty to allow php execution but could not find how to do it.

Kindly help me in this regard. Thanks


ANSWERS:


Easy as boiling an egg!

{php}echo "hello!"{/php}

Second link down, for reference.

Edit as of Smarty 3.1:

As of Smarty 3.1 the {php} tags are only available from SmartyBC.

Source:


Find the file smarty.class.php in your host directory

Go to smarty.class.php

Edit var $php_handling = SMARTY_PHP_ALLOW;

Save the file in server.

Now you may add php in tpl file as <?php ....code.... ?>


You may have seen the documentation, but you have missed {php}:

The {php} tags allow PHP code to be embedded directly into the template. They will not be escaped, regardless of the $php_handling setting. This is for advanced users only, not normally needed and not recommended.

Emphasis mine, source:

Note that putting PHP in template code is the easiest way to shoot yourself in the foot - the main purpose of Smarty is to separate PHP code and HTML templates. In other words, the mere fact of using this tag is a serious red flag; in most cases, it is possible to fix the underlying issue, and avoid PHP inside the template altogether.


Have you tried to enable error reporting?

error_reporting(E_ALL);
ini_set("display_errors", true);


 MORE:


 ? Create custom page in Prestashop 1.5.3
 ? How to create a new page in prestashop admin panel?
 ? Confused about prestashop PDF generated process. Where is the code to handle the logic?
 ? How to integrate prestashop with android?
 ? Create product from a module in prestashop
 ? Acces Prestashop webservice from JavaScript
 ? add a field in edit product page of prestashop admin
 ? Strange Characters in database text: Ã, Ã, ¢, â‚ €,
 ? Facebook Like Button Causing Horizontal Scrollbar
 ? How to call a php function inside a smarty .tpl file?