smarty 静态页面

来源:互联网 发布:盛世网络剧在线观看 编辑:程序博客网 时间:2024/05/21 11:00
section.php
<?php
require "smarty.inc.php";//加载模板引擎
$tpl->assign('title',"section循环");

$contact= array(
array('name'=> '孙某','fax'=> '1234', 'email' => 'luo@123','phone' => '123456'),
array('name'=> '随某','fax'=> '1234', 'email' => 'luo@123','phone' => '123456')
);

$tpl->assign('contact',$contact);
$tpl->display('section.tpl');
$output = $tpl->fetch("section.tpl");
//输出静态页面的路径
$PageName = "./section.html";
$fp = fopen($PageName,"w");
fwrite($fp,$output);
fclose($fp);
?>

section.tpl

<!DOCTYPE HTML>
<HTML lang="zh-CN">
<head>
<title>联系人信息表</title>
</head>
<body>
<table border ="1" width ="80%" align ="center">
<caption><h1>联系人列表</h1></caption>
<tr>
<th>姓名</th><th>传真</th><th>电子邮件</th><th>联系电话</th>
</tr>
<{section  name=line loop=$contact}>
</tr>
<td><{$contact[line].name}></td>
<td><{$contact[line].fax}></td>
<td><{$contact[line].email}></td>
<td><{$contact[line].phone}></td>
</tr>
<{sectionelse}>
<p>数组$contact中没有任何值</p>
<{/section}>
</table>
</body>
</html>


有图有真相:











原创粉丝点击