【问题标题】:Fatal error in SmartySmarty 中的致命错误
【发布时间】:2014-05-17 11:26:11
【问题描述】:

致命错误:未捕获--Smarty:无法加载模板文件 'H.tpl'

你好, 当我尝试运行一个聪明的程序时,我会遇到这个胎儿错误。我不知道如何消除这个错误。 我创建了两个文件,一个用于 .php,另一个用于 .tpl

PHP 文件: HelloWorld.php

//This is a simple comment use in php file 

require './libs/Smarty.class.php';//require function  includes Smarty class  
require 'demo/templates/H.tpl';

$smarty=new Smarty;// instantiates an object $smarty of class Smarty


$smarty->caching =true;//enable the caching  

$smarty->assign ('name', 'hello world');//used to assign values to the templates

$smarty->display ('H.tpl');//this is used to display the template

?>

TPL 文件: H.tpl

<html>

<head>

  <title>My first Smarty program</title>

</head>

<body>

  {*This is a comment line of smarty *}

  {$name}{*Smarty will replace the assigned content *}

</body>

</html>

【问题讨论】:

  • 它说它找不到 H.tpl - 检查你的路径和文件是否存在,PHP 等可以读取等等等等。
  • 使用 smarty 前必须配置模板目录
  • 默认情况下 smarty 模板在模板目录中。所以你应该把文件 H.tpl 放到这个目录中
  • 你创建了templates_c吗?此文件夹的写入权限?

标签: php html smarty


【解决方案1】:

你不应该这样做:

require 'demo/templates/H.tpl';

因为它不是 PHP 文件。

当你想显示 tpl 文件时,你很简单:

$smarty->display ('H.tpl');

或在 tpl 文件中,您可以使用包含其他文件

{include file="info.tpl"}

但你不必也不能在纯 PHP 中包含这些文件

如果您的文件 HelloWorld.php 在主目录中,则文件 H.tpl 应放在模板目录中,而不是在 demo/templates 目录中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    • 2022-11-10
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多