逐个检查
- 先开启PHP的错误提醒,一目了然:
<?php
error_reporting(E_ALL); - 确保模版文件存在:路径正确,可读,且有内容
注意路径,可以尝试使用绝对路径,例如 /var/www/website/smarty/hello.tpl - 检查版本,PHP7环境下,需要smarty v3.1.7以上
- 确保各个文件夹存在且可读写:
$smarty->template_dir
$smarty->compile_dir
$smarty->cache_dir
【注意:v3以上,$smarty->template_dir文件夹路径,不是字符串了,而是数组了,请print_r看一下,compile_dir等没改】
(Mac/Linux下sudo chmod -R 0777 /path/to/folder) - 注意函数$smarty->fetch( $tpl )不会显示内容,只会返回字符串,
要么echo $smarty->fetch( $tpl );
要么$smarty->display( $tpl ); - 尝试清空错误的缓存,$smarty->clear_all_cache();
- 最奇葩的一个错误原因:网页背景色是白色,文字也是白色,so...