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

I have the 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 the $smarty.capture.diff and $smarty.const.UPDATE_BLOCK_SECONDS , they display the correct value (for example, 98969 and 86400), but the {if} statement does not work and always prints the value โ€œdisable updateโ€

+4
source share
2 answers

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} 
+4
source
 {capture name="diff"} {datediff timestamp=$data_base.updated_date} {/capture} 

contains spaces.

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

may be what you are looking for.

+1
source

Source: https://habr.com/ru/post/1403208/


All Articles