Smarty输出空白页面

The*_*ian 5 php smarty

求助:模板文件出错

我有这样的Smarty设置:

require_once 'smarty/Smarty.class.php';
$smarty = new Smarty();

$smarty->compile_dir = $compile_dir;
$smarty->template_dir = $tpl_dir;
Run Code Online (Sandbox Code Playgroud)

这就是我现在应该需要的......我为其他网站设置了完全像这样的Smarty,它在同一台服务器上工作得很好.

var_dump($smarty)输出所有的公共变量和$smarty->template_exists("index.tpl")回报1,这既表明Smarty的正确设置和工作,但是,无论是$smarty->display("index.tpl")$output = $smarty->fetch("index.tpl"); echo $output;输出空白页.index.tpl文件肯定包含HTML.

我忘记了一些步骤还是什么?

编辑:

添加

ini_set('display_errors', true);
error_reporting(E_ALL + E_NOTICE);
Run Code Online (Sandbox Code Playgroud)

还为Smarty创建了配置目录.

并尝试过$output = $smarty->fetch("index.tpl"); var_dump($output).

还是空白页面.

如果我echo "foo";$smarty->display("index.tpl")它之前输出该行,但是如果我在它之后执行它,则它不会输出它.

Sun*_*hra 10

更改templates_c目录的权限.

  • 确切地说,您需要为所有用户允许写入权限:使用"chmod 777 filename" (2认同)

The*_*ian 1

我在模板文件中有额外的{foo.bar}(没有$)变量,这些变量应该在代码中稍后实现,假设Smarty只会将这些变量替换为空白,我认为这不会是导致问题的变量,但是在删除它们之后,它工作得很好。