程式需求
Smarty requires PHP 4.0.6 or later.
安裝
一、下載 http://www.smarty.net/download.php 及解壓,例如解壓到 /path/to/smarty/
二、建立目錄於解壓的smarty 目錄中 "templates", "configs", and "templates_c", "cache"
$ chmod 777 cache/
$ chmod 777 templates_c
三、SELinux打開寫入權限
$ chcon -t httpd_sys_rw_content_t /path/to/smarty/templates_c -R
$ chcon -t httpd_sys_rw_content_t /path/to/smarty/cache -R
四、PHP程式的引用
include "path/to/smarty/Smarty.class.php";      //讀入SMARTY函式庫
初始宣告 Smarty() 類別
$view = new Smarty();
五、Smarty 的常數設定
$SITE_ROOT = "smarty/";
$view->template_dir = $SITE_ROOT . "/templates/";
$view->compile_dir = $SITE_ROOT . "/templates_c/";
$view->config_dir = $SITE_ROOT . "/configs/";
$view->cache_dir = $SITE_ROOT . "/cache/";
$view->left_delimiter = '{{';
$view->right_delimiter = '}}';
六、樣版變數的指定
以下範例指定樣板中變數 $test 的值
$view->assign("test","This is a Test String");
以下範例在網頁中顯示樣板 index.tpl
$view->display('index.tpl');
七、樣板的使用範例
index.tpl
<body>
這是一個範例 {{$test}} 
</body>
整理 2009-02-21 01:55:48