{if} {else}在smarty中无法正常工作

时间:2012-03-24 09:41:26

标签: php smarty smarty3 smarty2

我在模板上有以下智能代码

{capture name="diff"}
    {datediff timestamp=$data_base.updated_date}
{/capture}

{$smarty.capture.diff} | {$smarty.const.UPDATE_BLOCK_SECONDS}

{if $smarty.capture.diff > $smarty.const.UPDATE_BLOCK_SECONDS}
    enable update
{else}
    disable update
{/if}

当我同时打印变量$smarty.capture.diff$smarty.const.UPDATE_BLOCK_SECONDS时,它们输出正确的值(例如98969和86400),但{if}语句不起作用并始终打印值“禁用更新”< / p>

2 个答案:

答案 0 :(得分:4)

请尝试

{if 0+$smarty.capture.diff > 0+$smarty.const.UPDATE_BLOCK_SECONDS}
  enable update
{else}
  disable update
{/if}

{if (int)$smarty.capture.diff > (int)$smarty.const.UPDATE_BLOCK_SECONDS}
  enable update
{else}
  disable update
{/if}

答案 1 :(得分:1)

{capture name="diff"}
    {datediff timestamp=$data_base.updated_date}
{/capture}

包含空格。

{capture name="diff"}{datediff timestamp=$data_base.updated_date}{/capture}

可能就是你要找的东西。

相关问题