【问题标题】:Smarty: Disabling include errorsSmarty:禁用包含错误
【发布时间】:2014-07-29 19:05:23
【问题描述】:

我在 index.html 中包含的模板很少。索引负责输出站点中的每个页面。 我像这样包含它们:

{include file="`$show`_contentleft.tpl"}

由于某种原因,不需要任何这些模板。

所以如果我没有模板,就会出现 smarty 错误:

Uncaught --> Smarty: Unable to load template file

它应该被跳过。我怎样才能禁用它?

【问题讨论】:

    标签: php smarty


    【解决方案1】:

    如果我理解正确,您可以简单地删除这些行或使用以下方法对其进行评论:

    {*  {include file="`$show`_contentleft.tpl"}  *}
    

    编辑

    解释后可以使用file_exists 完成,但您还需要包含目录结构。

    例如在我的 index.php 中我有:

    $smarty->setTemplateDir('templates');
    

    所以在我的模板中我必须使用:

    {if file_exists("templates/`$show`_contentleft.tpl")}
        {include file="`$show`_contentleft.tpl"}
    {/if}
    

    如果我没有在file_exists 中使用正确的路径,file_exists 将永远找不到此文件,因此无论$show 的值如何,都不要包含此文件。

    【讨论】:

    • 好吧,我不是这个意思。我在模板文件夹中没有模板文件。例如,我有 about_contentleft.tpl,但没有 services_contentleft.tpl,其中“about”和“services”是 $show 变量。关键是跳过它们或避免它们。不知何故 {if fileexist()} 不能正确设置 $template_dir 。我在其他项目中看到这包括不会引发错误。我也想做同样的事……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多