Page 1 of 1

Problem with conditionality

Posted: Fri May 30, 2008 9:13 pm
by Milhaus
Im trying to learn Smarty better. I have following template for Eventslisting module:

Code: Select all

{foreach from=$items item="item"}
{if $item.end > $smarty.now}
 <h3>{$item.short}</h3>
{/if}
{/foreach}
The obvious meaning is that if event ends in the past, the event shouldn't be displayed. I have events showed in attachment. 1. event should be displayed, while second shouldn't. But it doesn't work. If it's

Code: Select all

{if $item.end < $smarty.now}
, then all events are displayed, in opposite case none are displayed.

What am I doing wrong?

Re: Problem with conditionality

Posted: Fri May 30, 2008 9:20 pm
by calguy1000
You can't compare dates that way.

if you want to compare dates you ether have tod o it in the database, or convert the dates back to unixtime (integer)

Re: Problem with conditionality

Posted: Fri May 30, 2008 9:51 pm
by Milhaus
Thanks. I will look at it. Strange is that default template for that module uses similar construct...

Re: Problem with conditionality

Posted: Sat May 31, 2008 1:18 am
by Nullig
Sorry for the problem Milhaus with the module. I'll be uploading a fix.

The line should be:

{if $item.end < $smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}

Nullig

Re: Problem with conditionality

Posted: Sat May 31, 2008 1:55 pm
by calguy1000
yeah, in order to compare dates in that way they have to be all integers, not strings (with the month name)
still the better method would be to convert them all to unix timestamps and do the comparison there.