未捕获异常'SmartyException',消息'Smarty中缺少模板名称 [英] Uncaught exception 'SmartyException' with message 'Missing template name in SMARTY

查看:22
本文介绍了未捕获异常'SmartyException',消息'Smarty中缺少模板名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望更改具有条件的块的内容(isset($FILE)),但在运行代码时看到缺少模板名称的错误

public function food_list()
{
    $m_food=new M_food();
    $arr=$m_food->food_list();
    $smarty=new Smarty_restaurant();
    $smarty->assign("title","New food");
    //$smarty->assign("file","../../views/v_food_list.tpl");
    //$smarty->assign("arr",$arr);
    $smarty->display ("food_list.tpl");
}

这是Food_list.tpl文件

{extends file="index.tpl"}
{block name="head"}{include file="head-food.tpl"}{/block}
{block name="slide"}{/block}
{if isset($file)}
{block name="content"}{include file=$file}{/block}
{else}
{block name="content"}{/block}
{/if}

在添加//在$Smarty->Assign("file","../../views/v_Food_list.tpl")之前添加//时出现缺少模板名称的错误 我的问题需要一个详细的答案,请帮帮我。非常感谢

推荐答案

问题是{block}是在编译Smarty文件之前编译的,因此您应该尝试将Smarty文件更改为:

{extends file="index.tpl"}
{block name="head"}{include file="head-food.tpl"}{/block}
{block name="slide"}{/block}
{block name="content"}
{if isset($file)}
{include file=$file}
{/if}
{/block}

这篇关于未捕获异常'SmartyException',消息'Smarty中缺少模板名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆