//一般来说这种全局变量放在单独的一个文件中,便于维护
$html_code_file_root = "../html/";
$tpl = new integratedtemplateextension($html_code_file_root);
//指定要替换 tag 的 html 文件
$tpl->loadtemplatefile("goodslist.htm");
$tpl->setvariable("username",$username); //用户名称
//指定外层 block 名称
$tpl->setcurrentblock("goodslist");
我喜欢在循环前将循环次数单独赋值
$goodstypecount = count($goodstypearray);
//对外层block 进行循环
for ($i = 0 ; $i < $goodstypecount ; $i++)
{
$tpl->setvariable("type",$goodstypearray[$i]); //货物种类
//指定里层block 名称
$tpl->setcurrentblock("goodslistofsometype");
$goodsnamearraycount = count( $goodsnamearray[$i] );
//对里层block 进行循环
for($j = 0; $j < $goodsnamearraycount; $j++ )
{
//替换html 文件中的 tag
$tpl->setvariable(array ("goodsname" =>$goodsnamearray[$i][$j],
"price" => $goodspricearray[$i][$j]));
$tpl->parsecurrentblock(); //这里也可以写 $tpl->parse("goodslistofsomety
| 对此文章发表了评论 |
