|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sarahfoxnz Smarty Regular
Joined: 11 Apr 2010 Posts: 76
|
Posted: Sat Jan 30, 2016 2:43 am Post subject: Finding values NOT 0 |
|
|
Code: | {foreach from=$ONE key=k1 item=v1}
{if $v1 >0}
<strong>{$k1|capitalize}</strong>: {$v1}<br />
{/if}
{/foreach}
|
Hello.
I have the above script in a template & have identified a small problem.
Basically the values of $ONE are usually numbers - 5, 10, 134 etc... & the above lines work fine as $v1 is over 0.
Sometimes the value of $v1 is a time
1:20:00 (1 hour 20 mins)
24:00:00 (24 hours.)
This works fine - as the time is shown on the resulting HTML. However,
if v1 is 0:0:20, or 0:45:00 (20 secs or 40 minutes) it is not being displayed on the output.
Ive cahnged it now to the following, but it still doesnt work
Code: |
{if $v1 == 0}
{else}
<strong>{$k1|capitalize}</strong>: {$v1}<br />
{/if}
|
Can anyone advise a quick solution to cope with single (whole/integer) numbers and/or a time...
I'll like times under 1 hour to be shown.
PS about 1/3 or 1/2 of the values are times. and 1/3 of the times are under 1 hour.
Thank you |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Jan 30, 2016 2:48 pm Post subject: |
|
|
Solution is to fix your input data.
There should be no mix of types in the same cell.
Also, please switch to modern {foreach} syntax, which is much easier to read.
Code: | {foreach $ONE as $v}
{if $v > 0}
<strong>{$v@key|capitalize}</strong>: {$v|strftime:"%c"}<br />
{/if}
{/foreach} |
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Feb 01, 2016 12:36 am Post subject: |
|
|
Code: | {foreach from=$ONE key=k1 item=v1}
{if !is_numeric || $v1 >0}
<strong>{$k1|capitalize}</strong>: {$v1}<br />
{/if}
{/foreach} |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|