简体   繁体   English

Smarty中的致命错误

[英]Fatal error in Smarty

Fatal error:Uncaught--Smarty:Unable to load template file 'H.tpl'<--thrown in C:\\wamp\\www\\Smarty\\libs\\sysplugins\\smarty_internal_templatebase.php on line127 致命错误:未被捕获-聪明:无法加载模板文件'H.tpl'<-抛出于第127行的C:\\ wamp \\ www \\ Smarty \\ libs \\ sysplugins \\ smarty_internal_templatebase.php中

Hello , When i try to run a smarty program then i face this fetal error . 您好,当我尝试运行智能程序时,我将遇到此胎儿错误。 I don't know how to remove this error. 我不知道如何清除此错误。 I create two files, one for .php and another for .tpl 我创建两个文件,一个用于.php,另一个用于.tpl

PHP File : HelloWorld.php 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 File : H.tpl 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>

You should not do: 您不应该这样做:

require 'demo/templates/H.tpl';

at all because it's not PHP file. 根本没有,因为它不是PHP文件。

When you want to display tpl file you simple do: 如果要显示tpl文件,请执行以下操作:

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

or in tpl file you may include other files using 或在tpl文件中,您可以使用

{include file="info.tpl"}

But you dont' have to and cannot include those files in pure PHP 但是您不必也不能将这些文件包含在纯PHP中

And if your file HelloWorld.php is in main directory, file H.tpl should be placed in templates directory not in demo/templates directory. 并且,如果您的文件HelloWorld.php位于主目录中,则文件H.tpl应该放置在模板目录中,而不是在demo / templates目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM