field not displaying
ndwilliams3 - September 9, 2008 - 20:06
| Project: | Office Hours |
| Version: | 5.x-1.4 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
I am having trouble getting the field to display. I copied the body from contemplate into a custom node.tpl.php file but it is only displaying the h3 tag. below is the code.
<div class="field field-type-office-hours field-field-hours">
<h3 class="field-label">Hours of Operation</h3>
<div class="field-items">
<?php foreach ((array)$node->field_hours as $item) { ?>
<div class="field-item"><?php print $item['view'] ?></div>
<?php } ?>
</div>
</div>
#1
This is because there is no $item['view'], but an $item['day'], $item['starthours'], and $item['endhours'].
#2
can you be a little bit more specific?
i tried this:
<?php foreach ((array)$field_FIELDNAME as $item) { ?><?php print $item['day'] ?>
<?php echo t(' ') ?>
<?php print $item['starthours'] ?>
<?php echo t(' - ') ?>
<?php print $item['endhours'] ?>
<?php } ?>
i get this output:
6 9:00 - 20:00but i need:
Monday 9:00 - 20:00Tuesday 9:00 - 20:00
Wednesday 9:00 - 20:00
Thursday 9:00 - 20:00
Friday 9:00 - 20:00
Saturday 9:00 - 20:00
#3
The days are stored as integers, you'll need something like
$daykey= check_plain($item['day']);$days=array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'),3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday'));
$day= $days[$daykey];
for the day itself to show.
For some reason, you template displays only saturday. I'm not familiar with contemplate or the method you're pulling the $node->field_name, so i can't help you there.
#4
yeah i have found out that only the last day that you select appears on the site. but i have the same problem when i don't use a template:
Saturday 9:00 - 20:00instead
Monday 9:00 - 20:00Tuesday 9:00 - 20:00
Wednesday 9:00 - 20:00
Thursday 9:00 - 20:00
Friday 9:00 - 20:00
Saturday 9:00 - 20:00
Never mind, i use cck time, now