php - {if}{else} 在 smarty 中不能正常工作

标签 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} 语句不起作用并且始终打印值“禁用更新”

最佳答案

请试试

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

相关文章:

php - smarty 中的动态数组键

javascript - Smarty 将 id 分配给 {assign} 变量

php - 如何计算某列与另一个表的列匹配的行数

php - Sublime Text : in HTML links having PHP snippets, 符号突出显示红色?

php - 每个循环多个ajax php请求

php - 从MySQL表中选择信息与PHP多查询?

php smarty 语法错误

php - Prestashop $logged 和 $is_logged

replace - smarty 替换多个值

javascript - 将 Google AdWords 转化跟踪 (javascript) 代码添加到 PrestaShop/Smarty 页面中