(1) 我在根目錄下建立了新的目錄learn/,再在learn/裏建立一個目錄smarty/。將剛纔解壓縮出來的目錄的libs/拷貝到smarty/裏,再在smarty/裏新建templates目錄,templates裏新建cache/,templates/,templates_c/, config/
2) 新建一個模板文件:index.tpl,將此文件放在learn/smarty/templates/templates目錄下,代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
$smarty->template_dir = "smarty/templates/templates";
$smarty->compile_dir = "smarty/templates/templates_c";
$smarty->cache_dir = "smarty/templates/cache";
Hello,{$exp.name}! Good {$exp.time}
$hello[name] = “Mr. Green”;
Hello,Mr.Green! Good morning
{include file="header.tpl"}
{* body of template goes here *}
{include file="footer.tpl"}
模板文件中可以使用if else等判斷語句,即可以將一些邏輯程序放在模板裏。"eq", "ne", "neq", "gt", "lt", "lte", "le", "gte" "ge", "is even", "is odd", "is not even", "is not odd", "not", "mod", "div by", "even by", "odd by","==","!=",">", "<","<=",">="這些是if中可以用到的比較。看看就能知道什麼意思吧。
{if $name eq "Fred"}
Welcome Sir.
{elseif $name eq "Wilma"}
Welcome Ma'am.
Welcome, whatever you are.
{* this example will print out all the values of the $custid array *}
{section name=customer loop=$custid}
<script language=javascript>
function isblank(field) {
{ return false; }
{
return true;
}
}