偶还是对里面的parse方法不是太明白:(在index.dhtml里嵌套一个header.dhtml和footer.dhtml偶解决了。
大概是这样:
function run(){
$GLOBALS['_Loader']->import ('ext.PHPLib.Template');
$tpl = new Template( _TPL_PATH );
$tpl->set_file( array(
"index"  => "index.dhtml",
"header" => "header.dhtml",
"footer" => "footer.dhtml"
));
$tpl->set_var(array("PAGETITLE" => "主页"));
$tpl->parse("HEADER", array("header", "index")); $tpl->parse("FOOTER",array("index","footer"));
$tpl->p("FOOTER");
}那我想再嵌套一个登陆框的模板login.dhtml呢?如何弄咧?

解决方案 »

  1.   

    这种嵌套方式我不大喜欢,我还是用块方式比较好点。
    模板文件
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <link href="mo.css" rel="stylesheet" type="text/css">
    </head><body>
    <table width="700" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
      <tr> 
        <td height="18" colspan="6" background="images/background.gif">&nbsp;</td>
      </tr>
      <!-- BEGIN tdata -->
      <tr align="center" class="f1"> 
        <td width="80" height="22">{class_id}</td>
        <td width="99">{class_name}</td>
        <td width="105">{class_path}</td>
        <td width="202">{banzhu}</td>
        <td width="104">{class_order}</td>
        <td width="96">{class_flag}</td>
      </tr>
      <!-- END tdata -->
    </table>
    </body>
    </html>
      

  2.   

    替换程序
    <?
      $dir=".";
      require_once("config.inc");  //实例化一个模板类对象
      $tmplt=new Template();  //设定父模板文件句柄
      $tmplt->set_file("hd","templates/index.htm");  //设定和读入块
      $tmplt->set_block("hd","tdata","data");  $sql="SELECT * FROM xiaotao_forum";
      $result=$data_p->sql_query($sql) or $data_p->sql_error();
      $row=$data_p->sql_fetchrowset($result);
      $num=$data_p->sql_numrows($result);
      for($i=0;$i<$num;$i++)
      {
          $replace=array(
                         "class_id"      =>  $row[$i]["class_id"],
                         "class_name"    =>  $row[$i]["class_name"],
                         "class_path"    =>  $row[$i]["class_path"],
                         "banzhu"        =>  $row[$i]["banzhu"],
                         "class_order"   =>  $row[$i]["class_order"],
                         "class_flag"    =>  $row[$i]["class_flag"]
                   );
          //设定模板变量的替换值
          $tmplt->set_var($replace);      //先完成块的替换操作
          $tmplt->parse("data","tdata","true");
      }
      $data_p->sql_close();
      $tmplt->parse("out","hd");
      $tmplt->p("out");
    ?>
      

  3.   

    我只是给你一个使用块的建议,其实模板嵌套多个跟2个不是一样的,具体的phplib里template类的用法在 《PHP高级开发技术与应用》,清华大学出版社
    书号为:ISBN 7-302-05344-8/TP·3140中有详细介绍。
      

  4.   

    搞定,偶是被phplib的手册搞蒙了。呵呵,给分啦