faby
(faby)
新手上路

初级会员
UID 63968
精华
0
积分 32
帖子 28
金钱 32 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2005-4-3
状态 离线
|
phplib使用问题。
Use Template direcly or define a subclass of Template as needed.
Define a template file named page.ihtml as follows:
--------------------------------------------------------------------------------
<html>
<head><title>{PAGETITLE}</title></head>
<body bgcolor="#ffffff">
<table border=1 cellpadding=4 cellspacing=0 bgcolor="#eeeeee">
<tr>
<td colspan=2><h1>{PAGETITLE}</h1></td>
</tr>
<tr>
<td>{OUT}</td>
<td>Content</td>
</tr>
</table>
</body>
</html>
--------------------------------------------------------------------------------
This file contains a reference to the variable pagetitle and a reference to the variable named out. Another template file, named box.ihtml, contains a block named row with three variable references {TITLE}, {NUM} and {BIGNUM}:
--------------------------------------------------------------------------------
<!-- start box.ihtml -->
<table border=1 bgcolor="#cccccc" cellpadding=4 cellspacing=0>
<tr>
<td colspan=2><b>{TITLE}</b></td>
</tr>
<!-- BEGIN row -->
<tr>
<td>{NUM}</td>
<td>{BIGNUM}
</tr>
<!-- END row -->
</table>
<!-- end box.ihtml -->
--------------------------------------------------------------------------------
The following php3 file demonstrates how to use these templates:
--------------------------------------------------------------------------------
<?php include("./template.inc");
# create Template instance called $t $t = new Template("/page/to/webserver/template", "keep");
# define variables named page and box, referencing files $t->set_file(array( "page" => "page.ihtml", "box" => "box.ihtml"));
# extract the block named "row" from "box", creating a # reference to {rows} in "box". $t->set_block("box", "row", "rows");
# define the variables TITLE and PAGETITLE $t->set_var(array("TITLE" => "Testpage", "PAGETITLE" => "hugo"));
# define NUM and BIGNUM, then append "row" to "rows"... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array("NUM" => $n, "BIGNUM" => $nn)); $t->parse("rows", "row", true); }
# build out from box, then build out from page... $t->parse("OUT", array("box", "page"));
# finish out and print it. $t->p("OUT"); ?> <hr> <?php # report leftover variables, if any. print implode(", ", $t->get_undefined("rows")); ?> 上面的两行代码看不明白:
<?php $t->set_var(array("TITLE" => "Testpage", "PAGETITLE" => "hugo")); ?>
<?php $t->parse("OUT", array("box", "page"));
# finish out and print it. $t->p("OUT"); ?> 如果我想写三个文件,那么应该怎么设置
$->parse函数?
谢谢大家!
|
|