首页 > Web开发 > 详细

在smarty中通过php脚本给smarty赋值

时间:2016-03-07 17:03:32      阅读:327      评论:0      收藏:0      [点我收藏+]

一,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'); 

二,tpl 脚本(‘test.tpl‘) 


{{$arrInfo.smarty}}
------------
{{ php }} 
    //php给smarty变量赋值
    $this->_tpl_vars['name'] = 'hello world!'; 
   
{{/php}}
{{$name}}

三,显示

i am smarty!
------------
hello world!

在smarty中通过php脚本给smarty赋值

原文:http://blog.csdn.net/clevercode/article/details/50820012

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!