apache有权限写'/var/www/html/Smarty/templates_c/‘ 这个目录吗?你的test.htm放在那个目录里啊?

解决方案 »

  1.   

    保证你的templates_c和cache两个目录可写。把test.htm放到template里面。
      

  2.   

    确保那些目录都存在
    templates_c和cache必需可写
      

  3.   

    给你个sample
    index.php
    <?
      include_once('smarty/Smarty.class.php');
      $broadcast = '你好!!';
      //创建模板
      $smarty = new Smarty;
      $smarty->template_dir = './';
      $smarty->compile_dir = './templates_c/';
      $smarty->config_dir = './configs/';
      $smarty->cache_dir = './cache/';
      $smarty->left_delimiter = '{<';
      $smarty->right_delimiter = '>}';  $smarty->assign('broadcast',$broadcast);
      //显示模板
      $smarty->display('index.htm');
    ?>index.htm
    <HTML>
    smarty显示的信息:{<broadcast>}
    </HTML>
      

  4.   

    main.php文件如下
    <?php
    require ('./comm/smarty.class.php');
    define ('_SITE_ROOT','E:/smarty');
    $tp1=new smarty();
    $tp1->template_dir=_SITE_ROOT.'/templates/';
    $tp1->template_c=_SITE_ROOT.'/templates_c/';
    $tp1->config_dir=_SITE_ROOT.'/configs/';
    $tp1->cache_dir=_SITE_ROOT.'/cache/';
    $tp1->left_delimiter='{';
    $tp1->right_delimiter='}';
    ?>test.php文件如下
    <?php
    require ('main.php');
    global $tp1;
    $tp1->assign('title','测试用的网页');
    $tp1->assign('content','测试用的网页内容');
    $tp1->display('test1.html');
    ?>
    test1.html如下显示
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </HEAD>
    <BODY>
    {$title}
    <br/>
    {$content}
    </BODY>
    </HTML>
      

  5.   

    有错误的话smarty要有错误信息的,贴出来看看呀。
      

  6.   

    结贴:因为$smarty->template_dir='/var/www/html/Smarty/templates/',所以test.htm应该放到templates目录里面。多谢各位!