php - Is array in smarty 返回错误

标签 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 ...

我这样做了:

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

相关文章:

php - 是否可以使用 Smarty PHP 将数字格式化为小数点后两位

php - 如何在smarty中找到foreach循环的最后一个索引

php - 搜索公里内用户不起作用

php - 在 PHP 中解析视频 ID 的 youtube 视频链接的最合理方法是什么?

php - 如何在 Smarty 中为参数分配一个值数组?

php - 转义空白 : %20 or + - smarty

php - 从扩展模板调用时的 $smarty.current_dir 值

php - 如何使用 jquery、ajax 和 php 将图像文件 (BLOB) 保存在数据库中

php - 无法从 codeigniter 中的 mysql 表中获取一些特殊字符

php - 在 Bolt cms 中实现自定义用户/登录提供程序