我的模板上有以下聪明的代码
{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} 语句不起作用并且始终打印值“禁用更新”
最佳答案
请试试
{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}
关于php - {if}{else} 在 smarty 中不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9850664/