index.tpl的内容没有输出,去掉{include_php file="../header.php"}就可以了``不知道为什么`

解决方案 »

  1.   

    看index.tpl有没有编译,区分是编译错还是运行错。
      

  2.   

    index.tpl有没有编译,不知道怎么判断编译错还是运行错,帮忙看下哦 ``所有代码都在上面``你可以试试
      

  3.   

    你知道Smarty将index.tpl编译成一个PHP文件不?
      

  4.   

    既然用来template为什么还要向里面嵌入php文件呢?
      

  5.   

    $smarty->display('index.tpl')我感觉这样的解决很简单!
      

  6.   

    应该是你的include_path没有设定好把../libs的绝对路径添加到include_path里面
      

  7.   

    我知道Smarty将index.tpl编译成一个PHP文件,我怀疑是运行错误,路径是没问题的`=============================================================================
    既然用来template为什么还要向里面嵌入php文件呢?因为有时候网页的头部文件,比如菜单做成include就比较方便修改,这样就需要把头部文件include到index页面中,菜单又是动态的,所以就需要inlude php文件读取数据.大家平时都没遇到这样的问题吗?
      

  8.   


    lz还不太明白smarty的用法吧,多看看官方文档
      

  9.   

    模板之间也可以包含的, 这个知道是{inlude file="摸板文件"}这样吗?我先去官网看看``楼上的能详细说下吗?
      

  10.   

    比如:菜单的摸板meun.html,当然就有个meun.php(从数据库里动态读出菜单)的文件 display(meun.html);
    那我在index.html里<{include file="meun.html"}>,这样虽然meun.html包含进去了``但是这样只是静态的meun.html,而我需要是动态的,楼上的能详细说下吗?谢谢了 
      

  11.   


    貌似lz并不明白Smarty模板、PHP之间的关系。假设你的菜单是通过menu.tpl模板显示,
    你把menu.tpl里面需要现实的内容放到一个可以共享的区域,例如session或者global
    index.tpl里面包含menu.tpl,
    显示menu.tpl的时候不需要去调用menu.php,直接调用index.tpl所对应的php。menu.tpl可以自动从session或者global中提取内容,
    当然,menu.tpl也可以从index.tpl所对应的php中取得内容,
    但是这种结合共同处理内容的处理需要清晰的构架,又是另一个概念。不知道是否可以理解。
    一个tpl不等于一个php,更不等于一个页面——
    一个页面可以用n个tpl,一个php可以对应n个tpl,在一个页面的tpl可以用n个tpl组合。
      

  12.   

    header.php
    $display="正文";
    $smarty->assign("display",$display); 
    这里那来的$smarty object 啊,已经变成数组了require('../libs/Smarty.class.php');
    $smarty = new Smarty;$smarty->template_dir = 'templates';
    $smarty->compile_dir = 'templates_c';
    $smarty->config_dir = 'configs';
    $smarty->cache_dir = 'cache';
    include('header.php');//加在这里才对吧
    $smarty->display("index.tpl");
      

  13.   

    呵呵``楼上的解决方法,是正确的,我当时也是这样处理的===================================================menu.tpl可以自动从session或者global中提取内容, 
    当然,menu.tpl也可以从index.tpl所对应的php中取得内容, 
    但是这种结合共同处理内容的处理需要清晰的构架,又是另一个概念。 其实,我1直在想,既然选择了模板,为什么不能单独的模块去单独的去处理,而要选择这样从session或者global中提取 或者 这种结合共同处理内容的处理,那这样1来,smarty只能做到HTML和PHP分离,这样并不能来解决我们进行快速开发(需要什么功能就调用什么模块),那smarty的优势并没体现出来.或者你会告诉我用框架,但是在中,小型项目中用框架确实是没意义的,所以我才想到用smarty来做,这样smarty能实现吗?
      

  14.   

    不太对头....{include_php file="../header.php"} 逻辑关系比较是问题....
    最好是把php代码和tpl模板分开~~~
      

  15.   

    既然用来template为什么还要向里面嵌入php文件呢?
    -----------------------------------------------
    同问来着,但刚才google了下,找到了一个解决方案,同样也是答案简单的来说lz的include顺序有问题.
    lz原来的顺序是

    index.php 
        │
        └─index.tpl
              │
              ├─header.php
              └─header.tpl

    应该是

    index.php 
        │
        └─index.tpl
              │
              └─header.php
                    │
                    └─header.tpl
    应该在header.php中加入
    $smarty->display(header.tpl)这样当需要修改header.php或tpl 的时候不会牵涉到index的东西,我想这就是lz想要的效果吧..参阅资料
    froole兄15楼所言
    http://www.sherryping.cn/Mervin.G/?action=show&id=37&page=1
    http://lizi.blogbus.com/logs/10069282.html
      

  16.   

    刚写了个小节,关于smarty 文件嵌套调用,lz看看便知
    http://ph4r.wordpress.com.cn/2009/01/31/smarty-%e6%96%87%e4%bb%b6%e5%b5%8c%e5%a5%97%e8%b0%83%e7%94%a8/
      

  17.   

    Smarty的模板嵌套只能包含入别的模板,下面是我目前的一个实现:index.tpl:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>任氏有无轩</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta content="任氏有无轩" name="keywords" />
    <meta content="任氏有无轩" name="description" />
    <link href="../style.css" type="text/css" rel="stylesheet" />
    </head>
    <body>{include file="top.tpl" curPage="index"}<!--调用顶部导航条文件--><!--三大栏目块-->
    {include file="bottom.tpl"}<!--开始调用底部文件--></body>
    </html>
    top.tpl:
    <!--调用顶部LOGO栏文件-->
    {include file='logo.tpl'}<!--菜单导航条--><div class="menudiv" id="menu">
    <div class="float_left width_a">
    {if $curPage == "index"}
    <a href="/books/index.php" class="menua-cur" title="首 页">首 页</a>
    {else}
    <a href="/books/index.php" class="menua" title="首 页">首 页</a>
    {/if}
    </div>
    ...
    index.php:
        require ("../init.php");
        require_once ("functions.php");
        
        $sm->assign("thisyear", date("Y"));
        $sm->assign("summary", getSummary());
        
        $row1=getNewBuyBooks();
        $row2=getNewReadBooks();
        $row3=getMisc();    $sm->assign("row1", $row1);    
        $sm->assign("row2", $row2);
        $sm->assign("row3", $row3);
        $sm->display("book_index.tpl");
      

  18.   

    19楼的兄弟正解,谢谢了,但是你有个地方错了
    ==================================
    应该在header.php中加入 
    $smarty->display(header.tpl) =>改成 $this->display(header.tpl)这样就正常运行了`解决问题谢谢大家,人人有分,新年快乐!