1.解压后取libs文件,重命名为smarty
include_once("Smarty/Smarty.class.php");//包含smarty类文件
$smarty=new Smarty();//建立smarty实例对象
$smarty->config_dir="Smarty/Config_File.class.php";//目录变量
$smarty->caching=false;//不使用缓存
$smarty->template_dir="./templates";//设置模板目录
$smarty->compile_dir="./templates_c";//设置编译目录
$smarty->cache_dir="./smarty_cache";//缓存文件夹
$smarty->left_delimiter="{";
$smarty->left_delimiter="}";
2.创建smarty_inc.php,拷贝以上配置代码;
创建index.php,引入配置文件;
$name[ ]= array("name"=>"第一条目",“date”=>"2012-12-1");
$name[ ]= array("name"=>"第二条目",“date”=>"2012-12-1");
$name[ ]= array("name"=>"第三条目",“date”=>"2012-12-1");
$row=array("标题","作者","当前页面");
$smarty->assign("title",$name);
$smarty->assign("row",$row);
$smarty->display("index.htm");(无需写目录名$smarty->template_dir已声明!)
3.创建index.htm遍历数组;
<html>//不需要<body>
{$row[0] | $row[1] | $row[2]}
{section name=list loop=$title}
{$title[list].name}-{$title[list].date}
{/section}
</html>