{if}{else} do not work properly in smarty

Prakash picture Prakash · Mar 24, 2012 · Viewed 15.1k times · Source

I have following smarty code on my template

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

When I print both variable $smarty.capture.diff and $smarty.const.UPDATE_BLOCK_SECONDS, they output correct value (for example 98969 and 86400), but the {if} statement does not works and always print value "disable update"

Answer

Kokizzu picture Kokizzu · Mar 24, 2012

please try

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

or

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