Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 458
jawad waheed Avatar asked Sep 16 '11 15:09

jawad waheed


People also ask

What is TPL file in PHP?

TPL is a template file which is a common text file that contains user-defined variables that are entitled to be overridden by user-defined output content when a PHP web application parses the template file. These are used by web applications with server script PHP(but not restricted to) as a template file.

How does PHP Smarty work?

Smarty is a web template system written in PHP. Smarty is primarily promoted as a tool for separation of concerns. Smarty is intended to simplify compartmentalization, allowing the front-end of a web page to change separately from its back-end.

How does Smarty template work?

How does it work? Under the hood, Smarty compiles copies of the templates as PHP scripts. This way you get the benefits of both template tag syntax and the speed of PHP. Compilation happens once when each template is first invoked, and then the compiled versions are used from that point forward.


1 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: http://www.smarty.net/docs/en/language.function.php.tpl

like image 186
Prisoner Avatar answered Sep 26 '22 15:09

Prisoner