在index.php中包含top.php就可以了呀,用得着这么做吗?

解决方案 »

  1.   

    在index.php中include("top.php"),再将top.php的模板解析结果保存为一个变量(就是改改显示的部分)传递给index.php的模板处理部分。这样就可以把top.php输出重定向到index.php指定的部分。
      

  2.   

    include_once("top.php")不可以吗???????
      

  3.   

    index.html 
    里放一个 {top}set_file("top_template","top.html");
    ...
    对 top.html 模板进行处理处理后.
    set_file("index_template","index.html");
    parse("top","top_template");
    即可~~~~~~~
      

  4.   

    大家帮偶分析一下吧,运行index.php什么也没有显示。
    left.php文件如下
    <? $user=="abc";
             if($user=="abc"){
     $noname="good";
      }else{
     $noname="bad";}
     include "Template/template.inc"; 
             $tt = new Template("Template"); 
             $tt->set_file("MyFileHandle","left.htm");
             $tt->set_var("left",$noname);
             $tt->parse("MyOutput","MyFileHandle"); 
             $tt->p("MyOutput");
    ?>
    left.htm 如下
    {left}
    index.php如下
    <?
    include "Template/template.inc"; 
    $t = new Template("Template"); 
    $t->set_file("MyFileHandle","index.htm"); 
    $t->set_file("_left", "left.htm");
    $t->parse("left","_left"); 
    $t->parse("MyOutput","MyFileHandle"); 
    $t->p("MyOutput");
    ?>
    index.htm如下
    {left}
      

  5.   

    这样当然不行
    1、你没有运行left.php
    2、你没有在index.php中对模板变量left赋值
      

  6.   

    xuzuning(唠叨)
    老大,那样的话,是不是只能对include left.php 把lefp.php的内容用一个变量赋值,然后 就像allkill(傲气游) 大哥说的那样,把这个变量给index.php再输出去。这个left.php必须是纯php文本,不可以使用html混插了是不是??
      

  7.   

    没必要用top.php.直接用我跟你说的那种方法就行了吧
      

  8.   

    ccterran(iwind) 大哥
    小弟上次请教大哥是包含的是html文件,这次是包含的是php,需要用到两次模板解析,不知道如何操作了。根据allkill(傲气游)兄的指点,将整个php文件里同的内容当做一个变量来赋值可以运行出来,但是这个php文件就无法使用与html混 插了。
      

  9.   

    这个left.php必须是纯php文本,不可以使用html混插了是不是?
    你这个没有说清楚,我没有搞清楚你想干什么?
    既然都使用模板了,怎么还“使用html混插”呢?
    模板类的p方法为
    function p($varname) {
        print $this->finish($this->get_var($varname));
    }
    你可以派生或加一个result方法
    function result($varname) {
        return $this->finish($this->get_var($varname));
    }
    这样
    $s = $tpl->result();
    就取得了模板的处理结果而不输出如果嵌入的文件确实“使用html混插”了,也可以这样处理
    ob_start();
    include "left.php";
    $s = ob_get_contents(); //取回left.php的输出结果
    ob_end_clean();