Download & Extend

Date does not display

Project:Date
Version:5.x-1.3
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

$node->content['field_date'][0][#value'] is empty so I don't see a date when using <?print $content ?> in a theme. I've tried it using every type of widget. I'm using the site timezone option (-0800 'US/Pacific') I'm and not using the multiple option, I am using the required option.

This feels like I'm just missing something. I'm using date in conjunction with the calendar view module, which works fine, so the date is getting stored. I see it in $node->['field_date'][0]['value'] I just can't print it.

Comments

#1

Well, I've found a workaround, but there seems like there could be an easier way. Here's what I did:

<?php
$eventtime
= strtotime($node->field_date[0]['value']);
$eventtime = $eventtime - 28800; //this is -8 hours for my timezone
echo date('m/d/Y \a\t g:ia', $eventtime);
?>

I've been following the lessons in the Drupal-dojo (yea!) so maybe I'll look into seeing if I can figure out how to patch this. (if it is a bug in the first place)

#2

Status:active» fixed

The $node->content array does not contain any '#value' information. You are supposed to use
$node->content['field_date'][0][#view']
This contains the ready-to-display value, filtered and formatted with formatter that has been chosen for the field.

Setting this to fixed - feel free to reopen if you need further info.

#3

Just curious; why doesn't that show up when I print the whole object?

#4

Well, the $content variable in a node.tpl.php file should definitely contain HTML output for all the values, gathered from the ['#view'] values in $node->content.

#5

Status:fixed» closed (fixed)

#6

Version:5.x-1.2» 4.7.x-1.2

I am experiencing the same problem using Drupal 4.7 and Date module 4.7-1.2. Hope it's ok to post here; my issue is almost identical and this does not seem to be resolved. Thanks all for your work on this!

the $content variable in a node.tpl.php file should definitely contain HTML output for all the values, gathered from the ['#view'] values in $node->content

$content _should_ include the date information, but it does not seem to be the case here. The date field is not printed when the node is viewed, either as a full node or a teaser.

You are supposed to use
$node->content['field_date'][0][#view']
This contains the ready-to-display value, filtered and formatted

print_r($field_date) shows that $field_date does not seem to have a #view component, which may be causing the problem here.

Incidentally, list and table views display the date field properly (using the format set in the view).

IMHO, the root of this problem is probably related to the fact that $field_date is a non-standard field. Documentation for the module mentions creating $date objects (which include timezone information, and seem to lend themselves to re-formatting).

Might this be an issue with how cck, date module, and core fit together when printing fields that are non-standard?

Workaround: While it is possible to print $field_date[0][#value] in your tpl.php file, this will print the raw ISO date data from the database. One workaround for re-formating this data include using the strtotime php function (as described in the first post above). Another possibility is using the date formating capabilities of mySQL (I ended up doing this, even though it is probably not the most efficient way to do it).

#7

First of all, you changed the version and this works differently between 4.7 and 5.x, so the answer for 5.x won't apply.

The more general answer is that you should not rely on using something called $node->mydate[0]['value'] for many reasons, one of which is that there are reasons why the underlying data structure may change (as it did between 4.7 and 5.x). The best way to do this is not to use either 'value' or 'view', but to use the formatters, which should continue to work the same going forward in all versions:

<?php
print content_format('mydate', $node->mydate[0], 'default');
?>

where 'default' is changed to whatever format you want for the result. Many formats are already available:

  • default - the display you set up in your field settings form
  • long, medium, and short - either your site format for those values or whatever you changed those options to in 'Advanced Display Options' in your field settings form
  • iso - an iso-formatted date
  • ical - an ical-formatted date
  • feed - an rss-feed-formatted date

What is missing is a formatter that will return the raw db value, which I should add as another formatter option. I also need to get this documented.

#8

Version:4.7.x-1.2» 5.x-1.3
Status:closed (fixed)» active

I'm having this problem with 5.1. The field is simply not displaying in the body of my node. Here's an example:
http://region1success.dearmond.net/node/21

Between "Eligibility" and "Link" should be a date field called "Deadline". It appears in the Edit dialog, and I can change it but it won't show up in View mode.

I tried logging in as user=1 but it still doesn't display.

This date field is set to be just a date, with no time associated with it. Therefore, all timezone options are not entered. I have tried it with the selector and as text with the same result. The field is not required and is not set to multiple.

The date appears in my database.

Let me know if you want me to submit anything else.

Shawn

#9

Status:active» fixed

First of all, please quit re-opening closed issues and changing the version just because the title of the issue is the same general problem you're having. The previous discussion is about things that may or may not be related to what you're reporting and it just makes the issue impossibly difficult to follow. I appreciate the effort to see if something has already been reported before creating a new issue, but when you're switching from one version to another you're almost certainly reporting something that needs a new issue.

So open a new issue, but first:

1) Pick up the very latest development snapshot and see if your problem goes away with the latest code. Version 1.3 is getting dated and there have been lots of fixes since then. You need to do this to be sure you're not reporting something that is already fixed.

2) If you're having trouble seeing something in your node, switch back to an unaltered default theme to be sure the problem is not that you have done something to customize your theme that has created the problem. If you're using the Contemplate module, turn it off to be sure you haven't made changes there that are creating the problem.

3) If you cannot see your date displayed when you are using the latest code on an unaltered default theme, then open a new issue and report it, and include an export of your content type and field (using the content_copy module).

#10

Status:fixed» closed (fixed)