1. 寫一個配置文件smarty.ini.php:
<?PHP
//引用類文件?
require 'smarty/Smarty.class.php';
$smarty = new Smarty;
//$smarty=new Smarty;
//設置各個目錄的路徑,這裏是安裝的重點
$smarty->template_dir="templates/templates";
$smarty->compile_dir="templates/templates_c";
$smarty->config_dir="templates/config";
$smarty->cache_dir="templates/cache";
//smarty模板有高速緩存的功能,如果這裏是true的話即打開caching,但是會造成網頁不立即更新的問題,當然也可以通過其他的辦法解決
$smarty->caching=false;
?>
2. 在使用模板的index.php文件中:
<?php
include "smarty.ini.php";
$title="Smarty-Learn-Test";
$content="Smarty_content哈哈";
$auth="MarcoFly";
$website="www.MarcoFly.com";
$smarty->assign("title",$title);
$smarty->assign("content",$content);
$smarty->assign("auth",$auth);
$smarty->assign("website",$website);
$smarty->display("index.html");
?>
相應的index.html文件:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{$title}</title>
</head>
<body>
<p>內容:{$content}</p>
<p>作者:{$auth}</p>
<p>網址:{$website}</p>
</body>
</html>