Forums / Setup & design / Inconsistent if statement behaviour

Inconsistent if statement behaviour

Author Message

James Ward

Tuesday 29 July 2008 10:37:21 am

This is driving me nuts so any help would be much appreciated.

I use the same if statement in two places on my site. The basic goal of the statement is as follows:
If the event start date and the event end date are not the same and the event end date has content then show format the date field in the following way else format it another way without the end date.

Here is the statement I am using:

{if and(ne($event.data_map.start_date.content.timestamp,$event.data_map.end_date.content.timestamp),$event.data_map.end_date.content.timestamp)}
 {def $event_date = concat($event.data_map.start_date.content.timestamp|datetime( 'custom', '%M %d, %Y' ),' - ',$event.data_map.end_date.content.timestamp|datetime( 'custom', '%M %d, %Y' ))}
{else}
 {def $event_date = $event.data_map.start_date.content.timestamp|datetime( 'custom', '%M %d, %Y' )}
{/if}

When I run this code in my regular templates it works as expected. However I use the same code on the same event list in a pdf template and it does not work correctly. Blank dates are getting through as having content.

Inside the pdf I am getting dec 31, 1969 as an end date for events that did not have an end date entered.

Using attribute show I can see that the start timestamp has value, the end timestamp comes out as 0 and has_content appears as false but it still goes inside this if statement for some reason.

Have I stumbled upon a strange bug? Is there any reason an if statement would behave differently inside a pdf template?

working at www.wardnet.com
blogging at www.jamesward.ca

James Ward

Tuesday 29 July 2008 10:39:25 am

Whoops. Accidently cut and pasted some of my testing code. Here is the original code which works fine in my html template but breaks in a pdf template:

{if and(ne($event.data_map.start_date.content.timestamp,$event.data_map.end_date.content.timestamp),$event.data_map.end_date.has_content)}
 {def $event_date = concat($event.data_map.start_date.content.timestamp|datetime( 'custom', '%M %d, %Y' ),' - ',$event.data_map.end_date.content.timestamp|datetime( 'custom', '%M %d, %Y' ))}
{else}
 {def $event_date = $event.data_map.start_date.content.timestamp|datetime( 'custom', '%M %d, %Y' )}
{/if}

working at www.wardnet.com
blogging at www.jamesward.ca

James Ward

Tuesday 29 July 2008 10:59:52 am

Looking at it more closely I guess the problem would be better described as inconsistent has_content behavior. The other part of my if statement works fine, it shows just the start date if the two dates are equal. Unfortunately it tries to show both dates when the end date has no content.

working at www.wardnet.com
blogging at www.jamesward.ca

Ivo Lukac

Tuesday 29 July 2008 11:21:24 pm

Hi James,

In my experience there is no unique way to check if attribute has content. For date I would use data_int:
{$event.data_map.end_date.data_int}

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac