Uncaught exception 'SmartyException' with message 'Missing template name in SMARTY

本秂侑毒 提交于 2021-02-08 11:08:43

问题


I want change content of a block with a condition (isset($file)) but i saw an error Missing template name when i run my code

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");
}

And this is food_list.tpl file

{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}

I got an error Missing template name when i add // before $smarty->assign("file","../../views/v_food_list.tpl") I need a detail answer for my problem,please help me.Thank you so much


回答1:


The problem is that {block} are compiled before the rest of Smarty file, so you should try to change your Smarty file into:

{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}



回答2:


The reason is the variable $file is unset or empty. You should make sure your variable $file is not empty and its value is valid template path.



来源:https://stackoverflow.com/questions/26045425/uncaught-exception-smartyexception-with-message-missing-template-name-in-smar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!