Home > Backend Development > PHP Tutorial > 在smarty中通过php脚本给smarty赋值

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

WBOY
Release: 2016-06-23 13:15:04
Original
980 people have browsed it


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

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


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

三,显示i am smarty!
------------
hello world!
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template