Heim > Artikel > Backend-Entwicklung > 在smarty中通过php脚本获取smarty变量
一,php 脚本(test.php)
$smarty = new Sys_SmartyWork(CRON_HOME."/modifyInfo/tpl",CRON_HOME."/modifyInfo/tpl_c"); $hash = array();$info = array();$info ['smarty'] = 'i am smarty!';$info ['php'] = 'i am php';$hash['arrInfo'] = $info;//进行模板变量替换 $smarty->assign($hash); //编译并显示位于./templates下的index.htm模板 $msg = $smarty->display('test.tpl');
{{$arrInfo.smarty}}------------{{ php }} //php从smarty中获取变量值 $arrInfo = $this->_tpl_vars['arrInfo']; //输出 echo $arrInfo['php']."\r\n"; //php在模板中赋值给smarty变量 $this->_tpl_vars['myname'] = 'hello world!';{{/php}}{{$myname}}