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

eZ debug

Timing: Jan 30 2025 20:30:26
Script start
Timing: Jan 30 2025 20:30:26
Module start 'content'
Timing: Jan 30 2025 20:30:26
Module end 'content'
Timing: Jan 30 2025 20:30:26
Script end

Main resources:

Total runtime0.2305 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0080 588.0313370.2891
Module start 'content' 0.00800.0145 958.32031,005.6563
Module end 'content' 0.02240.2080 1,963.97663,895.4922
Script end 0.2304  5,859.4688 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00492.1355200.0002
Check MTime0.00140.6064200.0001
Mysql Total
Database connection0.00080.335410.0008
Mysqli_queries0.128455.68261410.0009
Looping result0.00150.66851390.0000
Template Total0.207690.010.2076
Template load0.00110.469910.0011
Template processing0.206589.569710.2065
Override
Cache load0.00080.344910.0008
Sytem overhead
Fetch class attribute can translate value0.00190.803010.0019
XML
Image XML parsing0.00030.115010.0003
General
dbfile0.00934.0502200.0005
String conversion0.00000.002130.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs