Home >Backend Development >PHP Problem >What is smarty php method

What is smarty php method

藏色散人
藏色散人Original
2020-08-28 10:11:422229browse

smarty php method refers to the "Smarty:php" function, and "{php}" is only available in SmartyBC, with syntax such as "{php}include('/path/to/display_weather.php') ;{/php}".

What is smarty php method

Recommended: "PHP Video Tutorial"

Smarty:php function

{php}

Important Note

Smarty has deprecated the {php} tag and it is strongly recommended not to use it. Please put your PHP logic into a PHP program or plug-in function.

Warm reminder:

In Smarty 3.1, {php} is only available in SmartyBC. The

{php} tag allows PHP code to be directly embedded in the template. Whether these codes are encoded depends on the setting of $php_handling.

Example 7.61. Use of {php} tag

{php}
   // including a php script directly from the template.
   include('/path/to/display_weather.php');
{/php}

Example 7.62. Use global variables in {php} tag to assign variables

{* this template includes a {php} block that assign's the variable $varX *}
{php}
   global $foo, $bar;
   if($foo == $bar){
     echo 'This will be sent to browser';
   }
  // assign a variable to Smarty
  $this->assign('varX','Toffee');
{/php}
{* output the variable *}
<strong>{$varX}</strong> is my fav ice cream :-)

See $php_handling, {include_php}, {include}, {insert} and componentized templates.

The above is the detailed content of What is smarty php method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn