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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 00:31:50
Script start
Timing: Jan 31 2025 00:31:50
Module start 'layout'
Timing: Jan 31 2025 00:31:50
Module start 'content'
Timing: Jan 31 2025 00:31:52
Module end 'content'
Timing: Jan 31 2025 00:31:52
Script end

Main resources:

Total runtime1.8433 sec
Peak memory usage8,192.0000 KB
Database Queries60

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0080 588.2500151.2266
Module start 'layout' 0.00800.0066 739.4766220.7031
Module start 'content' 0.01461.8274 960.17974,470.3125
Module end 'content' 1.84200.0013 5,430.492215.8438
Script end 1.8433  5,446.3359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00400.2183160.0003
Check MTime0.00150.0787160.0001
Mysql Total
Database connection0.00090.048310.0009
Mysqli_queries1.688691.6075600.0281
Looping result0.00070.0381580.0000
Template Total1.727393.720.8636
Template load0.00240.130020.0012
Template processing1.724993.573820.8624
Template load and register function0.00160.087710.0016
states
state_id_array0.00290.159710.0029
state_identifier_array0.00310.170520.0016
Override
Cache load0.00190.1013250.0001
Sytem overhead
Fetch class attribute can translate value0.00210.111320.0010
Fetch class attribute name0.00290.154760.0005
XML
Image XML parsing0.00850.459520.0042
class_abstraction
Instantiating content class attribute0.00000.001280.0000
General
dbfile0.04492.4361230.0020
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs