(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">
新建index.php,将此文件放在learn/下:
$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;
}
}