首先去www.smarty.net下載最新版的Smarty
把下載後的壓縮包在網站根目錄下解壓
tar -zxvf myindex Smarty.tar.gz
把解壓後的文件夾中的libs放到網站根目錄下,並且改名字爲smarty
然後在根目錄下建立下面兩個文件夾 templates 和 templates_c
最後在根目錄下編寫index.php 代碼如下:
<?php
include_once('./Smarty/Smarty.class.php');$smarty = new Smarty();
$smarty -> template_dir = "./templates"; //模板存放目錄
$smarty -> compile_dir = "./templates_c"; //編譯目錄
$smarty -> left_delimiter = "{{"; //左定界符
$smarty -> right_delimiter = "}}"; //右定界符
$smarty -> assign('test','OK');
$smarty -> display('test.html');
?>
在templates文件夾下編寫test.html 代碼如下
<html>
<head>
</head>
<body>
{{$test}}
</body>
</html>
最後更改templates_c的權限 chmod a+xwr templates_c
運行index.php測試
顯示 OK 就行了