Smarty 是什么?
为什么要使用它?
用例和工作流程
语法比较
模板继承
最佳实践
速成教程
{php} 标签已弃用 Smarty 中,不应使用。将其 PHP 逻辑放入 PHP 脚本或插件函数中。
从 Smarty 3.1 开始,{php} 标签只能在 SmartyBC 中使用。
{php} 标签允许 PHP 代码直接嵌入到模板中。无论 $php_handling 设置如何,都不会对它们进行转义。
示例 7.61 {php} 标签中的 php 代码
{php}
// including a php script directly from the template.
include('/path/to/display_weather.php');
{/php}
示例 7.62 {php} 标签与全局变量和分配变量
{* 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
$_smarty_tpl->assign('varX','Toffee');
{/php}
{* output the variable *}
<strong>{$varX}</strong> is my fav ice cream :-)
另请参见 $php_handling、{include_php}、{include}、{insert} 和 组件化模板。