最近公司使用ThinkPHP框架,因此比較關注,想到以前公司使用的框架用的模板引擎是 Smarty,並且用的還挺順手的。php
轉到使用ThinkPHP自帶的模板引擎還有點不習慣,因此在想換成Smarty模板引擎,網上看了一下,結果仍是比較簡單。html
以此記錄一下web
首先ThinkPHP框架裏面要有Smarty擴展 位置在 ThinkPHP\Extend\Vendor\Smarty ,若是沒有就去 Smarty官網下一個最新版吧,也推薦使用最新版的。通常完整版的ThinkPHP框架都含有 Smarty擴展的。 而後只需修改配置文件 Conf\config.php框架
<?phpreturn array( //'配置項'=>'配置值' 'TMPL_ENGINE_TYPE' => 'Smarty', 'TMPL_ENGINE_CONFIG' => array( 'caching' => TRUE, 'template_dir' => TMPL_PATH, 'compile_dir' => TEMP_PATH, 'cache_dir' => CACHE_PATH, 'left_delimiter' => '{', 'right_delimiter' => '}', ), );?>
Action:this
<?phpclass IndexAction extends Action { public function index(){ $data = array( 'asdf' => 1,'dfg' => 2,'asdfrg' => 3,'yhnfd' => 4,'bfws' => 1 ); $this->assign('test',$data); $this->display(); } }
html:code
{$smarty.now} <br /> {foreach $test as $key=>$data} {$key}:{$data}<br /> {/foreach}
最後輸出:orm
1411459827htm
asdf:1模板引擎
dfg:2it
asdfrg:3
yhnfd:4
bfws:1
yes,這樣就搞定了,使用Smarty模板就這麼簡單