<?php
include('libs/Smarty.class.php');
$a=new Smarty();
setcookie('name','dany');
$arr=array(1,2,3,4,5,6,7,8,9);
$a->template_dir="demo/templates";
$a->compile_dir="demo/templates_c";
$a->left_delimiter="<{";
$a->right_delimiter="}>";
$a->assign('array',$arr);
$a->display("cs.tpl");
——————————————————————————————————————————————上為php檔案
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<form action='cs.php' method="post">
<input type='text' name='page'>
<input type='submit' value='送出'>
</form>
</body>
</html>
——————————————————————————————————————————————————上為html檔案
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無标題文檔</title>
</head>
<body>
<{$smarty.cookies.name}>
<{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}>
<{foreach from=$array item=row name=a1}>
<{$row}>
<{/foreach}>
輸出<{$smarty.foreach.a1.total}>次<br>
<{section name=b loop=$array}>
<{$array[b]}>
<{/section}>
輸出<{$smarty.section.b.total}>次<br>
<{$smarty.get.page}>
<{$smarty.post.page}>
</body>
</html>
———————————————————————————————————————————————————上為tpl檔案