码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-03-07 17:05:18      阅读:164      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!