数组在smarty返回错误

Kar*_*rem 3 php smarty

Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "./templates/diet-report.tpl" on line 3 "{if is_array($dietcontent) }" - Unexpected " }"' in ...
Run Code Online (Sandbox Code Playgroud)

我这样做了:

    {if is_array($dietcontent) }
    There is something..
    {else}
    Noope...
    {/if}
Run Code Online (Sandbox Code Playgroud)

当我输出{$ dietcontent}时,我得到"数组".但在我没有得到"数组"的页面上我希望输出一个文本.

为什么我会收到错误?

我甚至尝试过我的控制器(上面是模板中):

$data['rapportExists'] = is_array($data['dietcontent']) ? true: false;
Run Code Online (Sandbox Code Playgroud)

然后在我的模板中:

{if $rapportExists == false }
noope
{/if}
Run Code Online (Sandbox Code Playgroud)

仍然收到相同的错误意外}

Oll*_*lli 5

你可以这样做:

{if $yourArray|is_array}
do something with it
{/if}
Run Code Online (Sandbox Code Playgroud)


Mic*_*ski 5

你需要删除之前的空间}.Smarty不会在闭合支撑之前或开口支撑之后允许空白.我在一些自己的模板中测试了这个,并且可以通过在结束括号前放置一个空格来重现您的错误.

{if is_array($dietcontent) }
-------------------------^^^

{if $rapportExists == false }
---------------------------^^^
Run Code Online (Sandbox Code Playgroud)