phplib的嵌套block问题

Arbow 2002-07-25 08:37:32
phplib具有block功能,可以把一部分代码重复显示。请问能否进行block的嵌套?

模板:1.tpl:
<table border="1">
<!-- BEGIN row -->
<tr>
<!-- BEGIN col -->
<td>{NUM}</td>
<!-- END col -->
</tr>
<!-- END row -->
</table>

php程序代码:
<?
include("./include/template.inc");
$t =new Template(".");
$t->set_file ("fHandle","1.tpl");
$t->set_block ("fHandle","row","rows");
for ($i=1;$i<5;$i++)
{
$t->set_block ("fHandle","col","cols");
for ($j=1;$j<5;$j++)
{
$num=$i*$j;
$code=$i.'*'.$j.'='.$num;
$t->set_var ("NUM","$code");
$t->parse ("cols","row",true);
}
$t->parse ("rows","row",true);
}
$t->parse ("out","fHandle");
$t->p("out");
?>

结果程序输出:
<table border="1">

<tr>
<!-- BEGIN col -->
<td>1*4=4</td>
<!-- END col -->
</tr>

<tr>
<!-- BEGIN col -->
<td>2*4=8</td>
<!-- END col -->
</tr>

<tr>
<!-- BEGIN col -->
<td>3*4=12</td>
<!-- END col -->
</tr>

<tr>
<!-- BEGIN col -->
<td>4*4=16</td>
<!-- END col -->
</tr>

</table>
的页面,可见里层的block没有被执行。



对此请问php高手们phplib能否进行嵌套block?如果,可以,麻烦给出修改后的程序,谢谢~~50分等着你:)
...全文
79 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
midiguy 2002-07-25
  • 打赏
  • 举报
回复
<?
include("./include/template.inc");
$t =new Template(".");
$t->set_file ("fHandle","1.tpl");
$t->set_block ("fHandle","col","cols");
$t->set_block ("fHandle","row","rows");

for ($i=1;$i<5;$i++)
{
for ($j=1;$j<5;$j++)
{
$num=$i*$j;
$code=$i.'*'.$j.'='.$num;
$t->set_var ("NUM","$code");
$t->parse ("cols","row",true);
}
$t->parse ("rows","row",true);
}
$t->parse ("out","fHandle");
$t->p("out");
?>

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧