Problem with conditionality

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
Milhaus

Problem with conditionality

Post 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?
Attachments
events_test.png
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Problem with conditionality

Post 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)
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Milhaus

Re: Problem with conditionality

Post by Milhaus »

Thanks. I will look at it. Strange is that default template for that module uses similar construct...
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Re: Problem with conditionality

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Problem with conditionality

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “Developers Discussion”