phplib中的template.inc.php应用
phplib的模板文件template.inc.php:
用法:实例化
$t= new Template("templates/");//参数为作为模板的HTML文件的相对路径
$t-
$t-
$t- $t-
对于循环的处理:
有循环的要在HTML模板的循环位置用>!-- BEGIN var1 -- <和> !-- END var1 -- <标明,必须单独成行,循环的关键字夹在中间。不同的循环块要用不同的var1值做区分。>
在PHP文件中用$t-
例程:
>?php
include "class.php";
$page=empty($_GET['page'])?1:$_GET['page'];
$lumid=empty($_GET['lumid'])?1:$_GET['lumid'];
$t= new Template("templates/");
if($lumid==4){
echo ">scrīpt
/scrīpt<";
}
if($lumid=='nvsh')
{
$lumid=12;
$t-
} else if ($lumid<=12 && $lumid>=15) {
$t-
}
else
$t-
$artlist= new Artlist;
$artlist-
$artlist-
$artlist-
$artlist-
$artlist-
$artlist-
$nextpage=$page+1;
$prepage=$page-1;
if($page>=1)$uppage=">a href='javascrīpt:window.alert(/"当前是第一页/")'
<上一页>
/a<";
else $uppage=">a href=?page=".$prepage."&lumid=".$lum."
<上一页>
/a<";
if($page<=$artlist-
a href='javascrīpt:window.alert(/"当前是最后一页/")'
<下一页>
/a<";
else $dopage=">a href=?page=".$nextpage."&lumid=".$lumid."
<下一页>
/a<";
$npage=$uppage."/".$dopage."/共".$artlist-
$t-
$t-
$t-
foreach($artlist-
{
$title=SubstrGB($result['title'],60);
$artlist=">a href='javascrīpt:showopen(/"articles.php?id=".$result['id']."&lumname=".$lumid."/")'<".$title.">/a<";
$time=$result['time'];
$t-
$t-
$t-
}
$t-
$t-
unset($artlist);
unset($t);
?<
用到模板的部分已经用红色标记出来了,套就行.
【作者: Liberal】【访问统计:】【2007年08月3日 星期五 19:17】【注册】【打印】
本文介绍了phplib中的template.inc.php模板文件的应用方法,详细解释了如何实例化模板对象及在HTML文件中嵌入变量、循环等内容。通过具体示例展示了如何在PHP中调用模板并填充数据。
387

被折叠的 条评论
为什么被折叠?



