這些天看到了smarty 3 alpha冒頭了,於是花時間做了個走訪調查。下面的文字基本上來自其readme:
基本文件文件結構
index.php /libs/ Smarty.class.php #主文件 /libs/sysplugins/ #內部plugin internal.* /plugins/ #外部plugin,可自由擴充 function.mailto.php modifier.escape.php /templates/ #模板,可以是純php或傳統的smarty模板 index.tpl index_view.php
一個經典的smarty調用
-
require('Smarty.class.php');
-
$smarty=newSmarty;
-
$smarty->assign('foo','bar');
-
$smarty->display('index.tpl');
和之前的版本似乎沒什麼差別
SINGLETON
這個有意義嗎?
-
$smarty= Smarty::instance();
模板
之前的smarty模板,相當於重新定義了一套標籤語言,那麼smarty3提供了一種新的模板形式,直接支持php語法的模板。
但是問題就出來了,我們還有必要用模板嗎?
引用php類型模板的一個例子:
-
$smarty->display('php:mytemplate.tpl');
模板中可以直接使用熟悉的語法: <?=$foo?> <?=$bar?>
使用php類型模板的話,安全問題需要自己解決。但這個對成熟的團隊來說不是問題。
除此之外,新支持字符串類型的模板,感覺比較生猛,離模板之路也是漸行漸遠:
-
$smarty->display('string:This is my template, {$foo}!');
smarty3的相關鏈接
- Smarty 3 Alpha with SVN-- 選擇googlecode提供的svn服務還是蠻省錢的
- smarty 3開發者郵件組