Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "./templates/diet-report.tpl" on line 3 "{if is_array($dietcontent) }" - Unexpected " }"' in ...
我这样做了:
{if is_array($dietcontent) }
There is something..
{else}
Noope...
{/if}
当我输出 {$dietcontent} 时,我得到“Array”。但是在我没有得到“Array”的页面上,我希望输出文本。
为什么会出现错误?
我什至在我的 Controller 中尝试过(上面是在模板中):
$data['rapportExists'] = is_array($data['dietcontent']) ? true: false;
然后在我的模板中:
{if $rapportExists == false }
noope
{/if}
仍然收到意外的相同错误
最佳答案
前需要去掉空格。 Smarty 不允许在右大括号之前或左大括号之后有空格。我在我自己的一些模板中对此进行了测试,并且可以通过在右大括号前放置一个空格来重现您的错误。
{if is_array($dietcontent) }
-------------------------^^^
{if $rapportExists == false }
---------------------------^^^
关于php - Is array in smarty 返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7447169/